Search Unity

Crash on Android dismissing rewarded video Monetization 3.0 plugin

Discussion in 'Unity Ads & User Acquisition' started by Antony-Blackett, Oct 30, 2018.

Thread Status:
Not open for further replies.
  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Screen Shot 2018-10-30 at 6.33.05 PM.png

    It seems there an error when releasing the ad or ad view or something like that.

    I've tried in Mono and Il2CPP same result.

    Works on iOS.
    Worked on Android with services ads plugin but not monetization 3.0
     
  2. DenisasK

    DenisasK

    Unity Technologies

    Joined:
    Oct 13, 2016
    Posts:
    89
  3. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I logged a bug with an attached project

    Case 1095893
     
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Hi, the log looked like it was the ad crashing only on Android, but on further investigation it's actually something in the callback on ad close. I'm looking into it further, i'm unsure why it only happens on android and with the latest monetization plugin.

    I'll keep you posted. I also updated the bug case with this info.

    Cheers.
     
  5. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Update:

    It's strange. If I move the stuff in the callback to happen in update the frame later, no crash, everything is fine. But I can't figure out why the crash happens.
     
  6. Nowlz

    Nowlz

    Joined:
    Nov 18, 2016
    Posts:
    55
    I'm seeing similar behaviour with Unity Ads supplied via AdMob mediation. When you dismiss a Unity Ad my application crashes but only on Android. Planning on doing more investigation this evening.
     
  7. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Same problem here ... Systematic crash when closing an ad on android (rewarded or interstitial) ... I am investigating in my side ...
     
  8. pikatch

    pikatch

    Joined:
    Sep 25, 2014
    Posts:
    1
    I'm having the same issue on my game, some phones crashes after watching an AD (interstitial). Do you confirm that Waiting the next frame corrects the issue ? Could be a simple workaround to make but I have no way to test it (can't reproduce the crash on my phones) ...
     
  9. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
  10. Nowlz

    Nowlz

    Joined:
    Nov 18, 2016
    Posts:
    55
    Here's what I'm seeing in the editor.log

    Code (CSharp):
    1. 0x00000001417BB06B (Unity) StackWalker::GetCurrentCallstack
    2. 0x00000001417BCD4F (Unity) StackWalker::ShowCallstack
    3. 0x0000000141796B60 (Unity) GetStacktrace
    4. 0x0000000140D4D25B (Unity) DebugStringToFile
    5. 0x0000000140D4DA3C (Unity) DebugStringToFile
    6. 0x0000000140E95113 (Unity) GeneralConnection::Connection::SendMessageA
    7. 0x0000000140E96239 (Unity) GeneralConnection::SendMessageA
    8. 0x000000014102F46E (Unity) ProfilerConnection::SetConnectedProfiler
    9. 0x0000000140E971BC (Unity) GeneralConnection::Disconnect
    10. 0x0000000140E9975C (Unity) GeneralConnection::Poll
    11. 0x0000000140E9BB1E (Unity) EditorConnection::PollWithCustomMessage
    12. 0x0000000141740482 (Unity) Application::TickTimer
    13. 0x000000014180C9CC (Unity) CrashCallback
    14. 0x000000014180E554 (Unity) WinMain
    15. 0x0000000141AF369C (Unity) strnlen
    16. 0x00007FF9EF533034 (KERNEL32) BaseThreadInitThunk
    17. 0x00007FF9F1721461 (ntdll) RtlUserThreadStart
     
  11. RossRothenstineU3D

    RossRothenstineU3D

    Unity Technologies

    Joined:
    Oct 26, 2018
    Posts:
    4
    Hello @Antony-Blackett ,

    Our initial investigation has found that it appears the callbacks aren't invoked on Unity's main thread on Android, but is doing so on iOS. It will be inconvenient, but for now you'll have to do the Unity GameObject manipulation on the next frame for Android.

    This will be fixed in our next patch release, and we will also be adding this as a test case for future releases. Thanks for reporting this!

    I also want to add that the
    startCallback
    is invoked on the UI thread, and calling it on the Main Thread can't be done because Unity is paused during Ad playback.

    RR
     
    Last edited: Oct 31, 2018
    marcinSandbox and pikatch like this.
  12. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778

    Ah ok,

    Good to know that my workaround fix is indeed the correct fix for the moment. Thanks for the quick response.

    Cheers,
    Antony.
     
    cantohi likes this.
  13. Nowlz

    Nowlz

    Joined:
    Nov 18, 2016
    Posts:
    55
    Any hint as to when the next patch may be released?
     
  14. Simone82

    Simone82

    Joined:
    Jun 20, 2016
    Posts:
    2
    hi, the problem in unit 2018.3.0f2 is the same. on Android it causes crashes at the beginning of the level that runs the script. If I do a build without ads, everything works. Reading around hypothesize that the problem occurs when the function returns NULL:

    private IEnumerator ShowAdWhenReady()
    {
    while (!Monetization.IsReady(placementId))
    {

    yield return new WaitForSeconds(0.25f);

    }

    ShowAdPlacementContent ad = null;


    ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;



    if (ad != null){
    ad.Show();

    }


    }
    any idea to bypass this problem?

    Ty!!
     
    gamearea3006 and Nightstriker like this.
  15. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
  16. mishakozlov74

    mishakozlov74

    Joined:
    Aug 8, 2018
    Posts:
    143
    Guys, please patch this issue.
    Seems like nothing has changed since October.
     
  17. marcinSandbox

    marcinSandbox

    Joined:
    May 25, 2017
    Posts:
    1
    @RossRothenstineU3D
    Any updates on this issue? When can we expect fix?
     
  18. cuervoxx

    cuervoxx

    Joined:
    Aug 30, 2018
    Posts:
    1
    same error here please fix en release 2018 f2
     
  19. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61

    Hey man, How did you do it?
    As in how did you move the stuff in the callback to happen in update the frame later? I have spent an entire day trying to figure it out. Nothing came of it.
     
  20. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61

    I am beginner to intermediate in scripting so those instructions you wrote goes over my head.
    Could you kindly tell me how I can solve this issue?
     
  21. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Code (csharp):
    1.  
    2.  
    3. static bool callbackCalled = false;
    4.  
    5. static void Callback()
    6. {
    7.    callbackCalled = true;
    8. }
    9.  
    10. void Update()
    11. {
    12.   if( callbackCalled )
    13.   {
    14.     DoCodeThatWasInCallback();
    15.     callbackCalled = false;
    16.   }
    17. }
    18.  
    It's a crap hack, but that's because it's working around a crap bug.
     
  22. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61
    and where am I putting the Callback function? Is it in Showresult.Finished?
     
  23. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61
    Thank you so much...I got it to work! haha
     
  24. OveRSoftware

    OveRSoftware

    Joined:
    Jun 18, 2015
    Posts:
    3
    How did you fix it?
    I tried to wait for 3 seconds and it works but when I load a new scene, the game crashes again. If I disable the Monetization.Initialize script it works.
     
  25. OveRSoftware

    OveRSoftware

    Joined:
    Jun 18, 2015
    Posts:
    3
    After wasting all day I finally tried the old method:
    - Enable built-in ads extension (in Services)
    - Use this code:
    using UnityEngine;
    using UnityEngine.Advertisements;

    public class UnityAds : MonoBehaviour
    {
    public void ShowAd()
    {
    if (!Advertisement.IsReady())
    {
    Debug.Log("Ads not ready for default placement");
    return;
    }
    Advertisement.Show();
    }
    }

    And it works... I don't understand why Unity's documentation recommends the other way
     
  26. Megalithic

    Megalithic

    Joined:
    Apr 21, 2014
    Posts:
    61

    I wouldn't know why that happens to be honest. I am not facing that issue. I am just setting a bool value to true when result == ShowResult.Finished. Then in the update function I Set another bool value to true and then make everything I need to do to award a player. Its working fine for me so far. Nothing goes wrong even when I change the scene. Basically what Antony-blackett in the previous posts did.
     
  27. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    127
    I had the exact same issue with AdMob in Unity. Thought it was a google bug, but it's exactly the same issue and the solution above works for AdMob too. I just change a boolean flag to true in the callback handler when the ad is closed and use update to test if it is true (although invoke might be better to only call it a few times a second rather than every frame).

    Hopefully this gets fixed soon!?
     
  28. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Make sure your callback and the boolean flag are both static. Otherwise you're going to run into the same crash when you try to set a bool that is a member of an object instance on the main thread.
     
    GeorgeCH likes this.
  29. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    I experience the same with AdMob Unity iOS - glad to see it wasn't an AdMob bug, but a Unity one!

    Anyway, for those so inclined, if you absolutely resent resorting to the Update loop or coroutines like I do, you can instead subscribe to the corresponding event with a non-anonymous delegate and to unsubscribe from it as soon as its outcome has been handled. Transitioning my game from a single- to multi-scene set up caused the issue to rear its ugly head - with a single-scene set up, I was able to rely on anonymous bool callbacks.

    EDIT: Doesn't work, seems like making any use of the callback causes the crash.

    Code (CSharp):
    1. public class UIWatchAdLayerController : UILayerController
    2. {
    3.  
    4.     private bool eligibleForVideoReward;
    5.  
    6.     public void WatchAd()
    7.     {
    8.         AdController.Instance.rewardedVideo.OnAdRewarded += HandleVideoAdRewarded;
    9.         AdController.Instance.rewardedVideo.OnAdClosed += HandleVideoAdClosed;
    10.         AdController.Instance.ShowRewardedVideo();
    11.     }
    12.  
    13.     private void HandleVideoAdRewarded(object sender, GoogleMobileAds.Api.Reward reward)
    14.     {
    15.         eligibleForVideoReward = true;
    16.     }
    17.  
    18.     private void HandleVideoAdClosed(object sender, System.EventArgs eventargs)
    19.     {
    20.  
    21.         AdController.Instance.rewardedVideo.OnAdRewarded -= HandleVideoAdRewarded;
    22.         AdController.Instance.rewardedVideo.OnAdClosed -= HandleVideoAdClosed;
    23.  
    24.         if (eligibleForVideoReward)
    25.         {
    26.             // Reward the user for watching the ad
    27.         }
    28.  
    29.         else
    30.         {
    31.             // Do not reward the user
    32.         }
    33.     }
    34. }
     
    Last edited: Feb 11, 2019
    MetalDonut likes this.
  30. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    127
    It seems to work fine even if the flag isn't static?! Also, Unity are aware of this bug and working on it, btw. Not sure on timings, but I assume* next update. *Ok, I "hope". :)
     
  31. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    Quick update - my code doesn't work, after all. It seems attaching anything at all to the callback triggers the crash. Guess it's coroutines/updates after all...
     
  32. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    This fixed the issue for me. Thank you.
     
  33. Haghshenas

    Haghshenas

    Joined:
    Apr 17, 2016
    Posts:
    2
    I use Invoke to put some delays to call whatever I need to do, It works for me like a charm.
     
  34. michaeldobele

    michaeldobele

    Joined:
    Oct 25, 2016
    Posts:
    10
    Was still crashing for me on Unity 2018.3.6f1 when using the AdMob Unity Plugin v3.16 directly when I would try to do some actions within the ad.OnAdClosed or ad.OnUserEarnedReward callbacks. Setting a bool instead and triggering my actions in Update() as suggested in this thread got me around the problem for now.
     
  35. the_othernet

    the_othernet

    Joined:
    May 25, 2016
    Posts:
    7
    Thank for for the Update() suggestion. Worked well.
     
  36. GameBelieve

    GameBelieve

    Joined:
    Feb 17, 2018
    Posts:
    6
    thanks men, its work,
     
  37. MaceB

    MaceB

    Joined:
    Jun 26, 2016
    Posts:
    9
    What am I doing wrong? I'm using Admob mediation and it's still crashing when I try to close the ad.

    Code (CSharp):
    1. static bool eligibleForReward;
    2.  
    3. void RequestRewardedAd()
    4. {
    5. //Code for requesting reward ad
    6. this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
    7. this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
    8. }
    9.  
    10. public void HandleRewardedAdOpening(object sender, EventArgs args)
    11.     {
    12.         InvokeRepeating("CheckIfRewardEarned", 4f, 0.5f);
    13.     }
    14.  
    15. static void HandleUserEarnedReward(object sender, Reward args)
    16.    {
    17.        eligibleForReward = true;
    18.    }
    19.  
    20. public void CheckIfRewardEarned() {
    21.         if (eligibleForReward) {
    22.             RewardUser();
    23.             eligibleForReward = false;
    24.             CancelInvoke();
    25.         }
    26.     }
     
  38. Mese

    Mese

    Joined:
    Dec 13, 2015
    Posts:
    41
    Hello,

    We have this error on all our games from time to time. Especially when the callback is directly modifiying Scene stuff like UI or something Unity Related. Our WorkAround is to pass all Callbacks through a "yield return new WaitForEndOfFrame();" Coroutine on our AdManager.

    I have two questions.
    1) The CoRountine purpose is to switch to Unity Thread. I mean, The coroutine might be fired outside Unity's Thread, but after the "yield return" is the Unity Thread who follows it, switching the thread to Unity's. The question is: Is there a better way to switch threads? I dont like to wait untill end of frame or "null" (next frame) or the Update hack.
    So, if I Start a Corountine but do not wait for anything, not executing "yield return" (or executing it after the callback) is that line switched to Unity's thread?

    2) When is this going to be fixed!? Any ETA?

    Thanks!
     
  39. cryogee

    cryogee

    Joined:
    Aug 6, 2009
    Posts:
    132
    Is this a recommended approach between Update vs Coroutine?

    I'm using Update method hack right now but I have UpdatoPhobia and dont like to put anything there.
     
  40. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @Mese, @cryogee

    The bug reported in the original post should have been fixed in January with 3.0.1 of the Ads SDK.
    I would recommend everyone upgrade to the latest version possible (currently 3.2.0 for direct integration and 3.1.0 for most mediation providers).

    If you continue to have issue, please submit a support ticket:
    unityads-support@unity3d.com

    It would be helpful if you provided the complete details of the issue you are having, along with the version of Unity, the version of the Ads SDK you are using, and the script you are using to integrate Unity Ads.
     
Thread Status:
Not open for further replies.