From a17bc383c719bffcae6bf7912f4191f1b022b07f Mon Sep 17 00:00:00 2001 From: 0O0o0oOoO00 <11174151+0o0o0oooo00@users.noreply.github.com> Date: Thu, 22 Jan 2026 11:23:20 +0800 Subject: [PATCH] fix: move lua state operation to pauser --- blcrack/cracker/cracker.cpp | 5 +++-- blcrack/cracker/cracker.hpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blcrack/cracker/cracker.cpp b/blcrack/cracker/cracker.cpp index 7ab248979..457ff5596 100644 --- a/blcrack/cracker/cracker.cpp +++ b/blcrack/cracker/cracker.cpp @@ -59,13 +59,13 @@ static fnset_TimeScaleT get_Time_set_timeScale() { LuaStatePauser::LuaStatePauser(lua_State* L) : m_L(L) {} -void LuaStatePauser::do_when_paused(const std::function& func) { +void LuaStatePauser::do_when_paused(std::function&& func) { auto _ = std::lock_guard(m_atomic_pause); ensure_debug_hook(); auto lk = std::binary_semaphore(0); g_pause_flag.store(&lk); - g_lua_state_operation.store(&func); + g_lua_state_operation.store(new std::function(std::move(func))); lk.acquire(); SPDLOG_INFO("lua operation finished"); } @@ -99,6 +99,7 @@ void LuaStatePauser::debug_hook(lua_State *L, lua_Debug *ar) { SPDLOG_INFO("pause triggered, operate lua state"); (*callback)(); auto f = g_pause_flag.load(); + delete g_lua_state_operation.load(); g_lua_state_operation.store(nullptr); g_pause_flag.store(nullptr); f->release(); diff --git a/blcrack/cracker/cracker.hpp b/blcrack/cracker/cracker.hpp index a49fbd453..a8c5fbec1 100644 --- a/blcrack/cracker/cracker.hpp +++ b/blcrack/cracker/cracker.hpp @@ -26,7 +26,7 @@ class LuaStatePauser { public: LuaStatePauser(lua_State* L); - void do_when_paused(const std::function& func); + void do_when_paused(std::function&& func); private: void ensure_debug_hook();