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

Unity game crashes when closing Reward Based Video Ad

我使用的是 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/AndroidRuntime:致命异常:main 进程: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);

}

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

我也遇到了这个问题。我使用 Instantiate(m_obj),用于 HandleUserEarnedReward 中的 null Object。所以不要忘记指向一个对象。