handzlikchris / FastScriptReload

Hot Reload implementation for Unity. Iterate on code insanely fast without breaking play session. Supports any editor. 1. Play 2. Make change 3. See results
https://immersivevrtools.com/projects/fast-script-reload
MIT License
1.58k stars 113 forks source link

ImmersiveVRTools.Common.Runtime: UnityMainThreadDispatcher can't be initialized on worker thread #134

Open mollstam opened 2 months ago

mollstam commented 2 months ago

Just got hit by an exception where code tried to get the .gameObject property from a worker thread. It was during SafeInvoke(HotReloadFailed, changesAwaitingHotReload); triggering ProjectWindowReloadStatusIndicatorDrawer.OnHotReloadFailed which in turn accesses UnityMainThreadDispatcher.Instance which in SingletonBase<T> will try to access stuff that should only be accessed on the main thread in case there is no singleton instance. Sorry for oral account of the callstack but my debugger got detached when I was poking around and CBA to repro. 😅

Anyway, maybe the main thread dispatcher needs to eaglery be inited from the main thread (RuntimeInitializeOnLoad?) if its means to be accessed from a worker, or just use another singleton implementation that doesn't hit Unity's API.

handzlikchris commented 2 months ago

Thanks - that could be an option. It may be a while before I get anywhere close to that as it doesn't happen to often (I think?). Feel free to submit PR if you've got a solution in mind already

mollstam commented 2 months ago

I will if I keep running into it, so far not annoying enough :)

On Tue, 6 Aug 2024 at 08:06, Chris Handzlik @.***> wrote:

Thanks - that could be an option. It may be a while before I get anywhere close to that as it doesn't happen to often (I think?). Feel free to submit PR if you've got a solution in mind already

— Reply to this email directly, view it on GitHub https://github.com/handzlikchris/FastScriptReload/issues/134#issuecomment-2270455605, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC6ELRVTHNWLMQPZQT5IJ3ZQBRWRAVCNFSM6AAAAABMBO7U72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZQGQ2TKNRQGU . You are receiving this because you authored the thread.Message ID: @.***>