Android c++ app crashes when setting reward video listener

  admob, android, c++, firebase

I’m adding AdMob rewards to my C++ android app with the fallowing code:

class RewardedVideoListener: public firebase::admob::rewarded_video::Listener {
public:
    //RewardedVideoListener() {}
    //RewardedVideoListener(FirebaseScene* scene) : scene(scene) {}
    void OnRewarded(firebase::admob::rewarded_video::RewardItem reward) override {
        //::LogMessage("Rewarding user with %f %s.", reward.amount, reward.reward_type.c_str());
        int a = 1;
    }
    void OnPresentationStateChanged(firebase::admob::rewarded_video::PresentationState state) override {
        int b = 1;
    }
};


static void OnRewardVideoInited(const firebase::Future<void>& future) {
    namespace rewarded_video = firebase::admob::rewarded_video;
    if (future.error() == firebase::admob::kAdMobErrorNone) {
        RewardedVideoListener rewarded_listener;
        rewarded_video::SetListener(&rewarded_listener);

        firebase::admob::AdRequest request = GetRequest();
        rewarded_video::LoadAd(kRewardedVideoAdUnit, request);
        rewarded_video::LoadAdLastResult().OnCompletion(OnRewardVideoLoaded);
    }
}


int AdMobC::showBanner() {
    firebase::App* app;
    app = ::firebase::App::Create(GetJniEnv(), GetActivity());
    firebase::admob::Initialize(*app, kAdMobAppID);

    // Start up rewarded video ads and associated mediation adapters.
    namespace rewarded_video = firebase::admob::rewarded_video;
    rewarded_video::Initialize();
    rewarded_video::InitializeLastResult().OnCompletion(OnRewardVideoInited);

    return 1;
}

whenever I add these lines:

RewardedVideoListener rewarded_listener;
rewarded_video::SetListener(&rewarded_listener);

I get ‘A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 in tid 18423 (adarts.fuelhunt), pid 18423 (adarts.fuelhunt)’

I wonder what am I doing wrong? I haven’t used C++ for a while.

Source: Windows Questions C++

LEAVE A COMMENT