From 30c7618fe5b718377f4b35d485ac04853a9e75ac Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 19 Oct 2024 20:39:49 +0200 Subject: [PATCH] Execute HTTP callbacks on main state not a thread --- src/controllers/plugins/api/HTTPRequest.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/controllers/plugins/api/HTTPRequest.cpp b/src/controllers/plugins/api/HTTPRequest.cpp index b10defcda..7e8200a15 100644 --- a/src/controllers/plugins/api/HTTPRequest.cpp +++ b/src/controllers/plugins/api/HTTPRequest.cpp @@ -128,11 +128,7 @@ void HTTPRequest::execute(sol::this_state L) return; } lua::StackGuard guard(L); - sol::state_view mainState(L); - sol::thread thread = sol::thread::create(mainState); - sol::state_view threadstate = thread.state(); - sol::protected_function cb(threadstate, *self->cbSuccess); - cb(HTTPResponse(res)); + (*self->cbSuccess)(HTTPResponse(res)); self->cbSuccess = std::nullopt; }) .onError([L, hack](const NetworkResult &res) { @@ -146,11 +142,7 @@ void HTTPRequest::execute(sol::this_state L) return; } lua::StackGuard guard(L); - sol::state_view mainState(L); - sol::thread thread = sol::thread::create(mainState); - sol::state_view threadstate = thread.state(); - sol::protected_function cb(threadstate, *self->cbError); - cb(HTTPResponse(res)); + (*self->cbError)(HTTPResponse(res)); self->cbError = std::nullopt; }) .finally([L, hack]() { @@ -177,11 +169,7 @@ void HTTPRequest::execute(sol::this_state L) return; } lua::StackGuard guard(L); - sol::state_view mainState(L); - sol::thread thread = sol::thread::create(mainState); - sol::state_view threadstate = thread.state(); - sol::protected_function cb(threadstate, *self->cbFinally); - cb(); + (*self->cbFinally)(); self->cbFinally = std::nullopt; }) .timeout(this->timeout_)