Search code examples
c#unity-game-enginecrashadmobandroid-runtime

Unity game crashes when closing Reward Based Video Ad


I'm using the sample code from the Google's AdMob documentation. The ad loads fine, but when I close it, the game just crashes. I don't really know what's causing the problem here. The script is attached to the AdManager game object, and the function showRewardVideoAd() is called when the user presses the button on RewardPanel.

Here is the logcat

2019-03-12 02:13:04.955 6457-7464/? E/CRASH: pid: 6457, tid: 7464, name: Thread-44 >>> com.reading.dj014296 <<< 2019-03-12 02:13:04.960 6457-7464/? E/CRASH: #00 pc 00805824 /data/app/com.reading.dj014296-0Sd1GzbLUymSTr_l2BN52w==/lib/arm/libunity.so 2019-03-12 02:13:04.960 6457-7464/? E/CRASH: #01 pc 00806f08 /data/app/com.reading.dj014296-0Sd1GzbLUymSTr_l2BN52w==/lib/arm/libunity.so 2019-03-12 02:13:04.960 6457-7464/? E/CRASH: #02 pc 00807100 /data/app/com.reading.dj014296-0Sd1GzbLUymSTr_l2BN52w==/lib/arm/libunity.so

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.reading.dj014296, PID: 6457 java.lang.Error: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000 Build fingerprint: 'samsung/dreamltexx/dreamlte:9/PPR1.180610.011/G950FXXU4ZSA5:user/release-keys' Revision: '10' pid: 6457, tid: 7464, name: Thread-44 >>> com.reading.dj014296 <<< r0 00000000 r1 00000001 r2 ab2212d0 r3 00000001 r4 00000002 r5 b4f68ed0 r6 ab2212d0 r7 00000000 r8 00000000 r9 ab2212d0 sl ab221340 fp 00000000 ip d38696a8 sp a961e1b8 lr d2f8e7a8 pc d2f8e824 cpsr 00001d28 at libunity.00805824(Native Method) at libunity.00806f08(Native Method) at libunity.00807100(Native Method)

public GameObject rewardPanel;
private string appID = "ca-app-pub-3940256099942544~3347511713";
private string adID = "ca-app-pub-3940256099942544/5224354917";
private RewardBasedVideoAd rewardBasedVideo;

// Start is called before the first frame update
void Start()
{
    MobileAds.Initialize(appID);

    this.rewardBasedVideo = RewardBasedVideoAd.Instance;


    // Called when an ad request has successfully loaded.
    rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
    // Called when an ad request failed to load.
    rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
    // Called when an ad is shown.
    rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
    // Called when the ad starts to play.
    rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
    // Called when the user should be rewarded for watching a video.
    rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
    // Called when the ad is closed.
    rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
    // Called when the ad click caused the user to leave the application.
    rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;



    RequestRewardAd();


}

private void RequestRewardAd()
{

    AdRequest request = new AdRequest.Builder().Build();
    this.rewardBasedVideo.LoadAd(request, adID);

}

public void showRewardVideoAd()
{

    if (this.rewardBasedVideo.IsLoaded())
    {
        this.rewardBasedVideo.Show();
    }
    else
    {
        Debug.Log("Opps... AD did not load");
    }
}

public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
}

public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    MonoBehaviour.print(
        "HandleRewardBasedVideoFailedToLoad event received with message: "
                         + args.Message);
}

public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
}

public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
}

public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
    RequestRewardAd();
}

public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
    rewardPanel.SetActive(true);
}


public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
}

public void RecieveReward()
{

    int wallet = PlayerPrefs.GetInt("WalletAmount");

    wallet += 100;
    PlayerPrefs.SetInt("WalletAmount", wallet);
    rewardPanel.SetActive(false);

}

Solution

  • Never mind, I found out that the problem was caused by loading a big texture that was on rewardPanel game object. The problem was solved by replacing the enormous texture with the smaller one.