luxonis / depthai-unity

DepthAI Unity Library, Unity projects and examples (OAK For Unity)
MIT License
200 stars 34 forks source link

Playground build dies when switching scenes on Linux #8

Closed sliwowitz closed 1 year ago

sliwowitz commented 2 years ago

I'm trying to run depthai-unity on Ubuntu with an OAK-D-Lite sensor. If I build the Playground scene, it dies when attempting to switch (sub)scenes by the arrow buttons, or the menu button.

I managed to build the shared libraries so that Unity can use them, the project loads fine and mostly works in the Editor (except for a possibly different issue #9). At first, this bug consistently happened to me in the Editor too. Now I can reproduce it in the Editor just occasionally, but it still happens every time if I run the built binary.

Device: OAK-D-Lite Unity: 2021.2.7f1

OS: Ubuntu 21.10 x86_64 Kernel: 5.13.0-27-lowlatency CPU: Intel i7-7820X @3.60 GHz, 8 physical cores GPU: NVIDIA TITAN RTX, driver version 470.86 Memory: 64 GB

Steps to reproduce:

0. Get the code

I'm using the beta branch.

1. Build depthai-core

cmake -S. -Bbuild -D'BUILD_SHARED_LIBS=ON'
cmake --build build --config Debug --parallel 8
cmake --build build --target install

2. Build depthai-unity shared library .so

Add SHARED keyword to the add_library directive in CMakeLists.txt, line 35, then run:

cmake -S. -Bbuild -D'BUILD_SHARED_LIBS=ON'
cmake --build build --config Debug --parallel 8

(BTW, even with these settings, libdepthai-resources.a is still built as a static library)

3. Copy the library to the project plugin folder

mkdir -p OAKForUnity/URP/Assets/Plugins/OAKForUnity/NativePlugin/Linux
cp build/libdepthai-unity.so OAKForUnity/URP/Assets/Plugins/OAKForUnity/NativePlugin/Linux
cp build/depthai-core/libdepthai-* OAKForUnity/URP/Assets/Plugins/OAKForUnity/NativePlugin/Linux

4. Convert the loader.mp4 video to webm

Unity complained about the loader.mp4 file Error while reading movie: ....../Playground/loader.mp4 and VideoClip import error for......./loader.mp4. On Linux, import of VP8 movies (.webm extension) is supported. So I converted the mp4 to webm using ffmpeg. The video plays fine in the editor. The command was ffmpeg -i loader.mp4 -c:v libvpx -crf 30 -b:v 0 -b:a 128k -c:a libvorbis loader.webm.

5. Open the project

6. Run in gdb

SIGXCPU is also thrown if a thread dies and gdb makes a pause - other threads are killed with SIGXCPU after you try to continue, there's also a bunch of uninteresting SIGPWR thrown, so first disable the SIGXCPU and SIGPWR traps before we get near the crash we want to see.

Go to where the build lives, run gdb ./Build1.x86_64

set mi-async 1
set pagination off
set non-stop on
handle SIGXCPU SIGPWR nostop noprint
run

Let the scene run, and just before you decide to switch scenes, go back to gdb, and press Ctrl+C

handle SIGXCPU stop print
continue

Switch back to the scene, click the menu button or the arrows. The scene hangs, and gdb has a stack trace ready:

Thread 70 "Build1.x86_64" received signal SIGXCPU, CPU time limit exceeded.
0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  ../sysdeps/unix/sysv/linux/sigsuspend.c: No such file or directory.
(gdb) 
Thread 60 "Loading.Preload" received signal SIGXCPU, CPU time limit exceeded.
0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  in ../sysdeps/unix/sysv/linux/sigsuspend.c

Thread 19 "Finalizer" received signal SIGXCPU, CPU time limit exceeded.
0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  in ../sysdeps/unix/sysv/linux/sigsuspend.c

(gdb) thread 19
[Switching to thread 19 (Thread 0x7fffa78af640 (LWP 164117))]
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  in ../sysdeps/unix/sysv/linux/sigsuspend.c
(gdb) bt
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
#1  0x00007fffa7f947ac in GC_suspend_handler_inner () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#2  0x00007fffa7f94665 in GC_suspend_handler () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#3  <signal handler called>
#4  0x00007ffff4ba2ff7 in __futex_abstimed_wait_common64 (private=<optimized out>, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7fffa82cf3f8) at futex-internal.c:57
#5  __futex_abstimed_wait_common (cancel=true, private=<optimized out>, abstime=0x0, clockid=0, expected=0, futex_word=0x7fffa82cf3f8) at futex-internal.c:87
#6  __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x7fffa82cf3f8, expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=<optimized out>) at futex-internal.c:139
#7  0x00007ffff4baea1f in do_futex_wait (sem=sem@entry=0x7fffa82cf3f8, abstime=0x0, clockid=0) at sem_waitcommon.c:112
#8  0x00007ffff4baeab8 in __new_sem_wait_slow64 (sem=0x7fffa82cf3f8, abstime=0x0, clockid=0) at sem_waitcommon.c:184
#9  0x00007fffa7f539a9 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#10 0x00007fffa7f1cee4 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#11 0x00007fffa7f1cda6 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#12 0x00007fffa7f961dc in GC_inner_start_routine () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#13 0x00007fffa7f95e6f in GC_start_routine () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#14 0x00007ffff4ba6927 in start_thread (arg=<optimized out>) at pthread_create.c:435
#15 0x00007ffff4c369e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

(gdb) thread 60
[Switching to thread 60 (Thread 0x7fff1010c640 (LWP 164158))]
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  in ../sysdeps/unix/sysv/linux/sigsuspend.c
(gdb) bt
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
#1  0x00007fffa7f947ac in GC_suspend_handler_inner () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#2  0x00007fffa7f94665 in GC_suspend_handler () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#3  <signal handler called>
#4  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#5  0x00007ffff75498de in vp8_loop_filter_bv_y_sse2 () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/UnityPlayer.so
#6  0x00007ffff635e4e0 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/UnityPlayer.so
#7  0x00007ffff635e3a3 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/UnityPlayer.so
#8  0x00007ffff66339f2 in ?? () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/UnityPlayer.so
#9  0x00007ffff4ba6927 in start_thread (arg=<optimized out>) at pthread_create.c:435
#10 0x00007ffff4c369e4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

(gdb) thread 70
[Switching to thread 70 (Thread 0x7ffe80207640 (LWP 164229))]
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
26  in ../sysdeps/unix/sysv/linux/sigsuspend.c
(gdb) bt
#0  0x00007ffff4b5480a in __GI___sigsuspend (set=0x7fffa82d11a0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26
#1  0x00007fffa7f947ac in GC_suspend_handler_inner () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#2  0x00007fffa7f94665 in GC_suspend_handler () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so
#3  <signal handler called>
#4  0x00007ffff4c381f4 in __libc_recvfrom (fd=57, buf=0x7ffe802044a0, len=40, flags=0, addr=..., addrlen=0x7ffe80204480) at ../sysdeps/unix/sysv/linux/recvfrom.c:27
#5  0x00007fffa6b613b3 in tcpip_get_devices () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/Plugins/libdepthai-core.so
#6  0x00007fffa6b603f3 in XLinkPlatformFindArrayOfDevicesNames () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/Plugins/libdepthai-core.so
#7  0x00007fffa6b58533 in XLinkFindAllSuitableDevices () from /home/strazce/hax/depthai-unity/OAKForUnity/URP/Build1_Data/Plugins/libdepthai-core.so
#8  0x00007fffa6b4804c in dai::XLinkConnection::getAllConnectedDevices (state=X_LINK_ANY_STATE) at /home/strazce/hax/depthai-unity/depthai-core/src/xlink/XLinkConnection.cpp:79
#9  0x00007fffa42d3a56 in DAIGetAllDevices () at /home/strazce/hax/depthai-unity/src/device/DeviceManager.cpp:51
#10 0x00007fffa42d4c5c in GetAllDevices () at /home/strazce/hax/depthai-unity/src/device/DeviceManager.cpp:173
#11 0x00000000402cae98 in ?? ()
#12 0x00007fff1c7f72a0 in ?? ()
#13 0x00007ffeeca4e120 in ?? ()
#14 0x00007ffeeca4e120 in ?? ()
#15 0x00007ffeeca4e120 in ?? ()
#16 0x00007fffa8867d20 in ?? ()
#17 0x0000000000000000 in ?? ()
(gdb) 
iamrajee commented 2 years ago

I'm facing the same issue with ubuntu 20.04 and unity 2021.2.7f

sliwowitz commented 1 year ago

I can't reproduce it now. Ubuntu 22.10 with Unity 2022.2.1f1 or 2012.3.16f1 LTS - same as https://github.com/luxonis/depthai-unity/issues/9#issuecomment-1380313563

gespona commented 1 year ago

Thanks for your patience and support @sliwowitz !