diff --git a/common/dangle/DangleContext.h b/common/dangle/DangleContext.h index adcf61a..ba11602 100644 --- a/common/dangle/DangleContext.h +++ b/common/dangle/DangleContext.h @@ -69,6 +69,7 @@ namespace dangle { using Op = std::function; bool destroy = false; + std::mutex destroyMutex; // Ops are combined into batches: // 1. A batch is always executed entirely in one go on the GL thread @@ -97,6 +98,8 @@ namespace dangle { // [JS thread] Add a blocking operation to the 'next' batch -- waits for the // queued function to run before returning void addBlockingToNextBatch(Op &&op) noexcept { + std::unique_lock lock(destroyMutex); + if (destroy) { DangleSysLog("addBlockingToNextBatch after DangleContext destroyed"); return; @@ -260,6 +263,11 @@ namespace dangle { }); } + ~DangleContext() { + std::unique_lock lock(destroyMutex); + DangleSysLog("~DangleContext()"); + } + static DangleContext *ContextGet(UDangleContextId dangleCtxId); static UDangleContextId ContextCreate(jsi::Runtime &runtime);