Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Get a thread exception in OneSignal Callback methods #543

Closed
1 task done
Arikaton opened this issue Oct 17, 2022 · 2 comments
Closed
1 task done

[Bug]: Get a thread exception in OneSignal Callback methods #543

Arikaton opened this issue Oct 17, 2022 · 2 comments

Comments

@Arikaton
Copy link

Arikaton commented Oct 17, 2022

What happened?

In callback method i use UnityEngine.Application.version which requires to be called on main thread. I suggest to dispatch onesignal callbacks in unity to main thread. Or update documentation for transparency. In OneSignal versions 2.* java code used unitySendMessage which guarantee that callback will be invoked in main thread.

In fresher versions OneSignal introduced a UnityMainThreadDispatch which only using for OneSiganl.Default.GetTags() calls. I suggest to wrap OneSignal.Default.NotificationOpened, OneSignal.Default.NotificationWillShow, OneSignal.Default.NotificationPermissionChanged in UnityMainThreadDispatch.Post(). Also i submitted a bug with UnityMainThreadDispatch, see #542

Steps to reproduce?

1. Install OneSignal 3.0.4
2. Use any main thread dependent api in OneSignal callback methods
3. Launch Android app
4. Send a notification from OneSignal console
5. Got an exception in OneSignal.Default.NotificationWillShow callback

What did you expect to happen?

The callbacks calls not in main thread in unity

Unity version

2020.3.32

OneSignal Unity SDK version

3.0.4

Platform

Android

Relevant log output

2022-10-17 12:56:15.517 19938-20182/com.game.game E/Unity: UnityException: get_version can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
      at AnalyticsTracker+<LogEventImplementation>d__10.MoveNext () [0x00000] in <00000000000000000000000000000000>:0

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Arikaton Arikaton changed the title [Bug]: Get a thread exception in [Bug]: Get a thread exception in OneSignal Callback methods Oct 17, 2022
@shepherd-l
Copy link
Contributor

Thanks for pointing out the issue with callbacks not being dispatched to the main thread. We plan to address this in the next major release

@shepherd-l
Copy link
Contributor

Apologies that this issue has gone stale. In v5 of our Unity SDK, we have changed it so that callbacks are invoked on the main Unity thread. I haven’t seen any further reports of this. Please try upgrading the OneSignal SDK and if this is still an issue, please open a new report with updated information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants