当关闭基于奖励的视频广告时,Unity游戏崩溃

时间:2019-03-12 01:22:44

标签: c# unity3d crash admob android-runtime

我正在使用Google AdMob文档中的示例代码。广告可以很好地加载,但是当我关闭它时,游戏便崩溃了。我真的不知道是什么引起了这里的问题。该脚本已附加到AdManager游戏对象,并且当用户按下RewardPanel上的按钮时,将调用showRewardVideoAd()函数。

这是 logcat

2019-03-12 02:13:04.955 6457-7464 /? E / CRASH:pid:6457,tid:7464,名称: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 / Android运行时:致命异常:主要     流程:com.reading.dj014296,PID:6457     java.lang.Error:信号11(SIGSEGV),代码1(SEGV_MAPERR),故障地址00000000     构建指纹:'samsung / dreamltexx / dreamlte:9 / PPR1.180610.011 / G950FXXU4ZSA5:user / release-keys'     修订:“ 10”     pid:6457,tid:7464,名称: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 在libunity.00805824(本机方法) 在libunity.00806f08(本机方法) 位于libunity.00807100(本机方法)

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);

}

2 个答案:

答案 0 :(得分:0)

没关系,我发现问题是由加载在rewardPanel游戏对象上的大纹理引起的。通过用较小的纹理替换巨大的纹理解决了该问题。

答案 1 :(得分:0)

我也遇到了这个问题。我使用Instantiate(m_obj)来表示Object中的空HandleUserEarnedReward。因此,不要忘记指向一个对象。

enter image description here