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

标签 c# unity-game-engine crash admob android-runtime

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

这是logcat

2019-03-12 02:13:04.955 6457-7464/? E/崩溃:pid:6457,tid:7464,名称:Thread-44 >>> com.reading.dj014296 <<< 2019-03-12 02:13:04.960 6457-7464/? E/崩溃:#00 pc 00805824/data/app/com.reading.dj014296-0Sd1GzbLUymSTr_l2BN52w==/lib/arm/libunity.so 2019-03-12 02:13:04.960 6457-7464/? E/崩溃:#01 pc 00806f08/data/app/com.reading.dj014296-0Sd1GzbLUymSTr_l2BN52w==/lib/arm/libunity.so 2019-03-12 02:13:04.960 6457-7464/? E/崩溃:#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 at libunity.00805824( native 方法) 在 libunity.00806f08( native 方法) at libunity.00807100( native 方法)

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游戏对象上的大纹理引起的。通过用较小的纹理替换巨大的纹理解决了这个问题。

关于c# - 关闭基于奖励的视频广告时 Unity 游戏崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112764/

相关文章:

c# - Asp Net Core 集成测试 - 方法不允许响应

c# - 如何从外到内用 Ninject 绑定(bind)装饰器?

c# - ProgressBar 十进制值

c# - 如何使用单个图像统一创建二维 map ?

android - (31,16) : error CS1525: Unexpected symbol `(' , 期望 `)' 、 `,' 、 `;' 、 `[' 或 `='

c# - 在完全笔直的赛道上比赛时间不一致

memory - 可能的内存问题导致 Hbase Thrift 服务器崩溃

c# - 获取 TFS 中工作区之间的最新信息和差异

android - 警报无限重复-锁定电话

android - Xamarin:启动另一个应用程序后 Android 应用程序崩溃