diff --git a/src/Battling/EventHooks/EventHook.hpp b/src/Battling/EventHooks/EventHook.hpp index 59628a2..833d412 100644 --- a/src/Battling/EventHooks/EventHook.hpp +++ b/src/Battling/EventHooks/EventHook.hpp @@ -39,9 +39,8 @@ namespace CreatureLib::Battling { free(_memory); if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; } size_t GetPosition() const noexcept { return _offset; } @@ -52,9 +51,9 @@ namespace CreatureLib::Battling { return; if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; + if (_offset + sizeof(T) >= _capacity) { _capacity += stepSize; auto newPtr = realloc(_memory, _capacity); @@ -74,9 +73,9 @@ namespace CreatureLib::Battling { void FinishListening() { if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; + _currentThread = nullptr; } private: diff --git a/tests/BattleTests/EventHookTests.cpp b/tests/BattleTests/EventHookTests.cpp index 668f091..5d540b5 100644 --- a/tests/BattleTests/EventHookTests.cpp +++ b/tests/BattleTests/EventHookTests.cpp @@ -41,5 +41,6 @@ TEST_CASE("Build and use event hook with different types", "[Battling]") { eventHook.Trigger(nullptr); eventHook.Trigger(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger(nullptr); + eventHook.FinishListening(); } #endif \ No newline at end of file