Closed cihadturhan closed 1 month ago
Hi @cihadturhan , the NullReferenceException
seems to be happening in OnInterstitialLoadFailedEvent
. Could you please check the implementation of that method instead of OnRewardedAdLoadFailedEvent
.
Hi @cihadturhan , the
NullReferenceException
seems to be happening inOnInterstitialLoadFailedEvent
. Could you please check the implementation of that method instead ofOnRewardedAdLoadFailedEvent
.
Hey, that’s my bad when posting here. But the issue is same for both OnRewardedAdLoadFailedEvent
AppLovin callbacks cannot execute Invoke
on android. I think this callbacks are called in threads other than main. Is it correct?
In my case, I converted function to static and called it directly instead of Invoke. So it’s resolved but this problem is still there
@cihadturhan Yeah most of the callbacks are called in background threads unless you specify otherwise. Could you try setting MaxSdkBase.InvokeEventsOnUnityMainThread = true;
and see if that helps?
Could you try setting
MaxSdkBase.InvokeEventsOnUnityMainThread = true;
Wow is there such a variable? I’ll try that in the next build. I sometimes see random crashes maybe that’s the reason.
Is there any drawbacks of running events on the main thread (ie freezing the ui or network requests)?
It would have the same drawbacks as putting the event in a Unity event function like Start() or Update(). Depending on the code in the callback there could be differences in performance, but for most cases there would likely be no difference.
Could you try setting
MaxSdkBase.InvokeEventsOnUnityMainThread = true;
and see if that helps?
Hi Jonathan, kinda related to this issue so I wanted to ask here. I saw some crashes and some devs reported it's because of the crashes in related to callbacks from Admob are not being called in the main thread.
Example: https://github.com/googleads/googleads-mobile-unity/issues/2854#issuecomment-1914807577
I wonder when I add MaxSdkBase.InvokeEventsOnUnityMainThread
, does it call MobileAds.RaiseAdEventsOnUnityMainThread = true
for Admob and other libraries too?
MaxSdkBase.InvokeEventsOnUnityMainThread
only ensures that our own callbacks from MaxSdkCallbacks.cs
are invoked on the main thread. It doesn't set MobileAds.RaiseAdEventsOnUnityMainThread
or similar in other libraries so it shouldn't be causing any crashes related to Admob callbacks.
MaxSdkBase.InvokeEventsOnUnityMainThread
only ensures that our own callbacks fromMaxSdkCallbacks.cs
are invoked on the main thread. It doesn't setMobileAds.RaiseAdEventsOnUnityMainThread
or similar in other libraries so it shouldn't be causing any crashes related to Admob callbacks.
Thanks for the response. I'm trying it now. I'm guessing it should be set before initialization of the SDK?
I'm assuming that even the other libraries call MaxSdkBase in other thread, the statement InvokeEventsOnUnityMainThread
will eventually call unity callbacks in the main thread.
It is best to set it prior to initialization, otherwise the onSdkInitializedEvent
might not be pushed to the main thread.
Closing this issue as I kinda resolved it.
Solution: never wait for a callback, instead set a boolean variable and check if the value is changed in update()
loop.
MAX Plugin Version
6.5.2
Unity Version
2022.3.22f1
Device/Platform Info
Android 10 - 11
Current Behavior
The code snippet below throws
NullReferenceException
when the it fails to load a rewarded ad.Expected Behavior
I'd expect
Invoke
function to be called without issues but it throwsNullReferenceException
for the called function name.How to Reproduce
OnLoad
after it's initializedAdditional Info
No response