From 52d0c9631e1fd20b58a308c059f550bf96253255 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 9 Aug 2025 12:18:35 +0200 Subject: [PATCH] fix(plugins): lookup by main lua state in http request (#6375) * fix(plugins): lookup by main lua state in http request * changelog --------- Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/controllers/plugins/api/HTTPRequest.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eab057c..d8bdab45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ - Bugfix: Emotes that failed to load their images now show as text. (#6355) - Bugfix: Fixed a crash that occurs when searching for emotes in channel-less contexts. (#6357) - Bugfix: Fixed command triggers showing as '/...' when the value is longer than the column width. (#6369) +- Bugfix: Fixed a crash that could occur when making HTTP requests from a timeout handler. (#6375) - Dev: Mini refactor of Split. (#6148) - Dev: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117) - Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129) diff --git a/src/controllers/plugins/api/HTTPRequest.cpp b/src/controllers/plugins/api/HTTPRequest.cpp index a270e815..9b4d45e9 100644 --- a/src/controllers/plugins/api/HTTPRequest.cpp +++ b/src/controllers/plugins/api/HTTPRequest.cpp @@ -115,9 +115,10 @@ void HTTPRequest::execute(sol::this_state L) auto hack = this->weak_from_this(); auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); pl->httpRequests.push_back(this->shared_from_this()); + auto *mainState = pl->state().lua_state(); std::move(this->req_) - .onSuccess([L, hack](const NetworkResult &res) { + .onSuccess([hack](const NetworkResult &res) { auto self = hack.lock(); if (!self) { @@ -127,11 +128,10 @@ void HTTPRequest::execute(sol::this_state L) { return; } - lua::StackGuard guard(L); (*self->cbSuccess)(HTTPResponse(res)); self->cbSuccess = std::nullopt; }) - .onError([L, hack](const NetworkResult &res) { + .onError([hack](const NetworkResult &res) { auto self = hack.lock(); if (!self) { @@ -141,18 +141,17 @@ void HTTPRequest::execute(sol::this_state L) { return; } - lua::StackGuard guard(L); (*self->cbError)(HTTPResponse(res)); self->cbError = std::nullopt; }) - .finally([L, hack]() { + .finally([mainState, hack]() { auto self = hack.lock(); if (!self) { // this could happen if the plugin was deleted return; } - auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(mainState); for (auto it = pl->httpRequests.begin(); it < pl->httpRequests.end(); it++) { @@ -167,7 +166,6 @@ void HTTPRequest::execute(sol::this_state L) { return; } - lua::StackGuard guard(L); (*self->cbFinally)(); self->cbFinally = std::nullopt; })