From fe05b5994cf4403c5069e225ae81c4f8d023848d Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Mon, 6 Jan 2025 22:18:39 +0100 Subject: [PATCH] Fix: Take Lua HTTP callbacks as sol::main_protected_function (#5800) Co-authored-by: Nerixyz --- CHANGELOG.md | 2 ++ src/controllers/plugins/api/HTTPRequest.cpp | 6 +++--- src/controllers/plugins/api/HTTPRequest.hpp | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b8ae37..f38527c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unversioned +- Bugfix: Fixed a crash relating to Lua HTTP. (#5800) + ## 2.5.2 - Bugfix: Fixed a crash in the 7TV EventApi when closing Chatterino. (#5768) diff --git a/src/controllers/plugins/api/HTTPRequest.cpp b/src/controllers/plugins/api/HTTPRequest.cpp index a1a97f61..a270e815 100644 --- a/src/controllers/plugins/api/HTTPRequest.cpp +++ b/src/controllers/plugins/api/HTTPRequest.cpp @@ -49,12 +49,12 @@ void HTTPRequest::createUserType(sol::table &c2) ); } -void HTTPRequest::on_success(sol::protected_function func) +void HTTPRequest::on_success(sol::main_protected_function func) { this->cbSuccess = std::make_optional(func); } -void HTTPRequest::on_error(sol::protected_function func) +void HTTPRequest::on_error(sol::main_protected_function func) { this->cbError = std::make_optional(func); } @@ -64,7 +64,7 @@ void HTTPRequest::set_timeout(int timeout) this->timeout_ = timeout; } -void HTTPRequest::finally(sol::protected_function func) +void HTTPRequest::finally(sol::main_protected_function func) { this->cbFinally = std::make_optional(func); } diff --git a/src/controllers/plugins/api/HTTPRequest.hpp b/src/controllers/plugins/api/HTTPRequest.hpp index ebf82967..82589410 100644 --- a/src/controllers/plugins/api/HTTPRequest.hpp +++ b/src/controllers/plugins/api/HTTPRequest.hpp @@ -48,9 +48,9 @@ private: int timeout_ = 10'000; bool done = false; - std::optional cbSuccess; - std::optional cbError; - std::optional cbFinally; + std::optional cbSuccess; + std::optional cbError; + std::optional cbFinally; public: // These functions are wrapped so data can be accessed more easily. When a call from Lua comes in: @@ -64,7 +64,7 @@ public: * @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds * @exposed c2.HTTPRequest:on_success */ - void on_success(sol::protected_function func); + void on_success(sol::main_protected_function func); /** * Sets the failure callback @@ -72,7 +72,7 @@ public: * @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status * @exposed c2.HTTPRequest:on_error */ - void on_error(sol::protected_function func); + void on_error(sol::main_protected_function func); /** * Sets the finally callback @@ -80,7 +80,7 @@ public: * @lua@param callback fun(): nil Function to call when the HTTP request finishes * @exposed c2.HTTPRequest:finally */ - void finally(sol::protected_function func); + void finally(sol::main_protected_function func); /** * Sets the timeout