exokitxr / exokit

Native VR/AR/XR engine for JavaScript 🦖
MIT License
997 stars 117 forks source link

Threads not cleaned on window destruction #1346

Closed avaer closed 5 years ago

avaer commented 5 years ago

Currently Exokit uses threads in the native bindings for things like decoding images. In a few of these cases the thread is either not destroyed or left dangling if the window disappears underneath it as in iframe destruction.

The current effect of this is random crashes on window destroy.

We'll need a more globally tracked thread system to ensure proper shutdown of these thread cases. This might take the shape of a thread pool.

avaer commented 5 years ago

It looks like there are ~7 cases of this in the native bindings.

deps/openvr/src/ivrcompositor.cpp:  vr::reqThead = std::thread([]() -> void {
deps/oculus/src/ovrsession.cpp:  oculusvr::reqThread = std::thread([]() -> void {
deps/exokit-bindings/magicleap/src/magicleap.cc:        std::thread([]() -> void {
deps/exokit-bindings/videocontext/src/VideoCamera.cpp:  std::thread([pFormatCtx, videoStream, pFrame, pFrameRGB, pLive, pMutex, pFrameReady]() mutable -> void {
deps/exokit-bindings/browser/src/browser.cpp:      browserThread = std::thread([dataPath{std::move(dataPath)}, frameworkPath{std::move(frameworkPath)}]() -> void {
deps/exokit-bindings/canvascontext/src/image-context.cc:    std::thread([this, buffer, byteLength]() -> void {
deps/exokit-bindings/glfw/src/glfw.cc:    std::thread([&]() -> void {
deps/exokit-bindings/webaudiocontext/src/Audio.cpp:    std::thread([this, webAudioAsync, buffer{std::move(buffer)}]() mutable -> void {
deps/exokit-bindings/webaudiocontext/src/AudioBuffer.cpp:    std::thread([this, webAudioAsync, buffer{std::move(buffer)}]() mutable -> void {