Skip to content

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

@Arikaton

Description

@Arikaton

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions