sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

C++ call lua module func will crash in release mode!

Open warsark opened this issue 1 year ago • 2 comments

sol2 3.3.1 vs2022 17.11.1 build with c++ 20 in x86 release mode crash(debug mode is ok...)

c++ code: `

try{ //ver1:call module function sol::table self = g_LuaState["abcmod"];//crash here

    sol::table rv = self["getResult"](1, 2, 3);

//ver2:call global function

sol::table rv = g_LuaState["getResult"](1, 2, 3);//sometimes will throw exception:stack index 1, expected string, received no value: bad get from protected_function_result (is not an error)

}

catch (const sol::error& err)//can not catch crash with module call

{

	ShowLuaException(err);

}

`

ver1:lua module code: ` abcmod={}; local this=abcmod; function doFunc1(a, b, c) return {[1]=2}; end

function doFunc2(a, b, c) return {[2]=3}; end

function this.getResult(a, b, c) local mapFuncs={ [1]=doFunc1, [2]=doFunc2, }; local func = mapFuncs[cid]; local retMap={}; if (func == nil) then return retMap; end

	return func(a, b, c);
end

return this; ver2:lua global function code: function doFunc1(a, b, c) return {[1]=2}; end

function doFunc2(a, b, c) return {[2]=3}; end

function getResult(a, b, c) local mapFuncs={ [1]=doFunc1, [2]=doFunc2, }; local func = mapFuncs[cid]; local retMap={}; if (func == nil) then return retMap; end

	return func(a, b, c);
end

`

warsark avatar Aug 24 '24 11:08 warsark

@warsark Please format your code correctly using markdown for further reference, because in its current form it is unlikely that someone will look into it.

deadlocklogic avatar Oct 02 '24 04:10 deadlocklogic

Even though it is ridiculous how this issue is presented, your issue is missing return this at the end of the lua module.

deadlocklogic avatar Oct 02 '24 11:10 deadlocklogic