From 53a7d6512f2d60f426b421225d98779f0228bf36 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 12 May 2021 22:44:58 -0400 Subject: [PATCH] lock when modifying components (#475) --- game/system/vm/vm.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/system/vm/vm.cpp b/game/system/vm/vm.cpp index a252534779..5dfd96df23 100644 --- a/game/system/vm/vm.cpp +++ b/game/system/vm/vm.cpp @@ -82,7 +82,9 @@ void subscribe_component() { throw std::runtime_error("[VM] Cannot add new components when VM is dead!"); } + status_mutex.lock(); ++components; + status_mutex.unlock(); // stall component until VM is ready if (status == Status::Uninited) { @@ -91,7 +93,9 @@ void subscribe_component() { } void unsubscribe_component() { + status_mutex.lock(); --components; + status_mutex.unlock(); vm_dead_cv.notify_all(); }