Mathijs-Bakker / Extenject

Dependency Injection Framework for Unity Game Engine
MIT License
512 stars 95 forks source link

ArgumentNullException when using UI Toolkit and Extenject on WebGL #55

Closed ANTONBORODA closed 2 months ago

ANTONBORODA commented 1 year ago

Describe the bug An "ArgumentNullException: Value cannot be null." appears when SceneContext is added to a scene with UI Document (UI Toolkit component) in scene and the project is built for WebGL. Also, the injection does not seem to happen after that error appears.

To Reproduce Steps to reproduce the behavior:

  1. Create an empty project.
  2. Create an empty UI Document (uxml) file.
  3. Add UIDocument MonoBehaviour to the scene, add the uxml file to it along with the default panel settings.
  4. Add Zenject/SceneContext MonoBehaviour.
  5. Build project
  6. Deploy/run the build. The error will appear in the browser console:

    ArgumentNullException: Value cannot be null. Parameter name: e at UnityEngine.UIElements.UQueryExtensions.Query (UnityEngine.UIElements.VisualElement e)

Expected behavior There should be no exception and the injection should happen

Screenshots InjectionBug

Extenject and Unity info:

Additional context The sample repro project is attached: UIToolkitIssue.zip

denravonska commented 1 year ago

I have exactly the same issue on Android using 2021.3.6f1.

11-18 11:23:42.035   669   688 E Unity   : ArgumentNullException: Value cannot be null.
11-18 11:23:42.035   669   688 E Unity   : Parameter name: e
11-18 11:23:42.035   669   688 E Unity   :   at UnityEngine.UIElements.UQueryExtensions.Query (UnityEngine.UIElements.VisualElement e) [0x00000] in <00000000000000000000000000000000>:0 
11-18 11:23:42.035   669   688 E Unity   :   at Zenject.SceneContext.Install () [0x00000] in <00000000000000000000000000000000>:0 
11-18 11:23:42.035   669   688 E Unity   :   at Zenject.SceneContext.RunInternal () [0x00000] in <00000000000000000000000000000000>:0 
11-18 11:23:42.035   669   688 E Unity   :   at Zenject.RunnableContext.Run () [0x00000] in <00000000000000000000000000000000>:0 
doctorseus commented 1 year ago

I assume this got introduced with https://github.com/Mathijs-Bakker/Extenject/pull/23. Could you test with a code-base based before this patch got introduced and if this fixes your issue (of course you would loose the injection behaviour)?

In general it would have to be checked why behaviour differs for WebGL as I assume it works for other platforms?

denravonska commented 1 year ago

I get the same on both Linux and Android so I assume it affects all platforms. On Linux it's not obvious as it results in a futex crash with some unknown frames in the trace.

Thread 28 "Finalizer" received signal SIGPWR, Power fail/restart.
[Switching to Thread 0x7fff305f86c0 (LWP 158504)]
__futex_abstimed_wait_common64 (private=<optimized out>, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7ffef2db63f8) at ./nptl/futex-internal.c:57
Download failed: Invalid argument.  Continuing without source file ./nptl/./nptl/futex-internal.c.
57  ./nptl/futex-internal.c: No such file or directory.
(gdb) bt
#0  __futex_abstimed_wait_common64 (private=<optimized out>, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7ffef2db63f8) at ./nptl/futex-internal.c:57
#1  __futex_abstimed_wait_common (cancel=true, private=<optimized out>, abstime=0x0, clockid=0, expected=0, futex_word=0x7ffef2db63f8) at ./nptl/futex-internal.c:87
#2  __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x7ffef2db63f8, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=<optimized out>) at ./nptl/futex-internal.c:139
#3  0x00007ffff48983af in do_futex_wait (sem=sem@entry=0x7ffef2db63f8, abstime=0x0, clockid=0) at ./nptl/sem_waitcommon.c:111
#4  0x00007ffff4898440 in __new_sem_wait_slow64 (sem=0x7ffef2db63f8, abstime=0x0, clockid=0) at ./nptl/sem_waitcommon.c:183
#5  0x00007ffef2a3abe1 in ?? () from project/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#6  0x00007ffef2a040f0 in ?? () from project/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#7  0x00007ffef2a03fb2 in ?? () from project/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#8  0x00007ffef2a7d4b8 in GC_inner_start_routine () from project/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#9  0x00007ffef2a7d14b in GC_start_routine () from project/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#10 0x00007ffff4890402 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#11 0x00007ffff491f590 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
denravonska commented 1 year ago

I assume this got introduced with #23. Could you test with a code-base based before this patch got introduced and if this fixes your issue (of course you would loose the injection behaviour)?

In general it would have to be checked why behaviour differs for WebGL as I assume it works for other platforms?

We just tried to disable line 298 through 307 and it seems to work fine for our case. Only tested Windows native so far. I expect Linux and Android to work as well.

ANTONBORODA commented 1 year ago

Can confirm commenting out the code introduced with #23 works.