Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
warsark opened this issue Aug 24, 2024 · 2 comments
Open

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

warsark opened this issue Aug 24, 2024 · 2 comments

Comments

@warsark
Copy link

warsark commented Aug 24, 2024

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 warsark changed the title C++ call lua module func will crash! C++ call lua module func will crash in release mode! Aug 24, 2024
@deadlocklogic
Copy link
Contributor

@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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants