Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Crash on Android dismissing rewarded video Monetization 3.0 plugin

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

  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,168
    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:
    64
  3. Antony-Blackett

    Antony-Blackett

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

    Case 1095893
     
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,168
    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,168
    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:
    45
    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:
    57
    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,082
  10. Nowlz

    Nowlz

    Joined:
    Nov 18, 2016
    Posts:
    45
    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,168

    Ah ok,

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

    Cheers,
    Antony.
     
  13. Nowlz

    Nowlz

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

    Simone82

    Joined:
    Jun 20, 2016
    Posts:
    1
    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 spsarras like this.
  15. ap-unity

    ap-unity

    Unity Technologies

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

    mishakozlov74

    Joined:
    Aug 8, 2018
    Posts:
    9
    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:
    60

    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:
    60

    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,168
    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.
     
    Baraff likes this.
  22. Megalithic

    Megalithic

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

    Megalithic

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

    OveRSoftware

    Joined:
    Jun 18, 2015
    Posts:
    2
    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:
    2
    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:
    60

    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:
    41
    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,168
    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:
    192
    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 at 1:02 PM
    MetalDonut likes this.
  30. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    41
    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:
    192
    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:
    192
    This fixed the issue for me. Thank you.