From 8a2f5d6666803ae5953fdbb09affb182b4417db0 Mon Sep 17 00:00:00 2001 From: tkzcfc Date: Tue, 18 Oct 2022 17:42:19 +0800 Subject: [PATCH] Fix downloader crash in the lua coroutine (#927) --- .../lua-bindings/manual/network/lua_downloader.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/scripting/lua-bindings/manual/network/lua_downloader.cpp b/extensions/scripting/lua-bindings/manual/network/lua_downloader.cpp index f72852f920..c007d42a62 100644 --- a/extensions/scripting/lua-bindings/manual/network/lua_downloader.cpp +++ b/extensions/scripting/lua-bindings/manual/network/lua_downloader.cpp @@ -31,6 +31,8 @@ THE SOFTWARE. #include #include +#include "scripting/lua-bindings/manual/CCLuaEngine.h" + USING_NS_AX; using namespace ax::network; @@ -217,7 +219,7 @@ static int lua_downloader_setOnFileTaskSuccess(lua_State* L) luaL_argcheck(L, lua_isfunction(L, 2), 2, "should be a function"); saveCallback(L, d, "setOnFileTaskSuccess"); - d->setOnFileTaskSuccess([d, L](const DownloadTask& task) { + d->setOnFileTaskSuccess([d, L = LuaEngine::getInstance()->getLuaStack()->getLuaState()](const DownloadTask& task) { int ret = getCallback(L, d, "setOnFileTaskSuccess"); // stack callbackfn if (ret) { @@ -249,7 +251,7 @@ static int lua_downloader_setOnTaskProgress(lua_State* L) luaL_argcheck(L, lua_isfunction(L, 2), 2, "should be a function"); saveCallback(L, d, "setOnTaskProgress"); - d->setOnTaskProgress([d, L](const DownloadTask& task) { + d->setOnTaskProgress([d, L = LuaEngine::getInstance()->getLuaStack()->getLuaState()](const DownloadTask& task) { int ret = getCallback(L, d, "setOnTaskProgress"); // stack callbackfn if (ret) { @@ -284,7 +286,8 @@ static int lua_downloader_setOnTaskError(lua_State* L) luaL_argcheck(L, lua_isfunction(L, 2), 2, "should be a function"); saveCallback(L, d, "setOnTaskError"); - d->setOnTaskError([d, L](const DownloadTask& task, int errorCode, int errorCodeInternal, std::string_view errorSt) { + d->setOnTaskError([d, L = LuaEngine::getInstance()->getLuaStack()->getLuaState()]( + const DownloadTask& task, int errorCode, int errorCodeInternal, std::string_view errorSt) { int ret = getCallback(L, d, "setOnTaskError"); // stack callbackfn if (ret) {