mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

New argument parser cannot handle nested arrays

Open FileEX opened this issue 1 year ago • 6 comments

Describe the bug

The new argument parser cannot correctly pass nested tables from Lua to C++. In the other direction, when returning from C++ to Lua, everything works fine. The problem arises when we try to use a nested table from Lua as a function argument.

This causes a crash

bool TestFunction(std::unordered_map<std::string, std::unordered_map<std::string, float>> tbl)
testFunctionTable({
    data = {first = 1},
})

Exception access violation. t->tt = 4 (LUA_STRING) image

Steps to reproduce

Above

Version

N/A

Additional context

No response

Relevant log output

No response

Security Policy

  • [X] I have read and understood the Security Policy and this issue is not security related.

FileEX avatar Sep 22 '24 20:09 FileEX

Where does the lua_next get called here? Whats the stack trace?

TracerDS avatar Sep 22 '24 21:09 TracerDS

Where does the lua_next get called here? Whats the stack trace?

>	lua5.1c_d.dll!lua_next(lua_State * L, int idx) Wiersz 1008	C	Symbole zostały załadowane.
 	client_d.dll!CLuaFunctionParserBase::PopUnsafe<std::unordered_map<std::string,float,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,float>>>>(lua_State * L, int & index) Wiersz 477	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaFunctionParserBase::PopUnsafe<std::unordered_map<std::string,std::unordered_map<std::string,float,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,float>>>,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::unordered_map<std::string,float,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,float>>>>>>>(lua_State * L, int & index) Wiersz 493	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaFunctionParserBase::Pop<std::unordered_map<std::string,std::unordered_map<std::string,float,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,float>>>,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::unordered_map<std::string,float,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,float>>>>>>>(lua_State * L, int & index) Wiersz 167	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaFunctionParser<1,0,&CLuaEngineDefs::TestFunction>::Call<>(lua_State * L) Wiersz 702	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaFunctionParser<1,0,&CLuaEngineDefs::TestFunction>::operator()(lua_State * L, CScriptDebugging * pScriptDebugging) Wiersz 736	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaDefs::ArgumentParser<&CLuaEngineDefs::TestFunction>(lua_State * L) Wiersz 100	C++	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_precall(lua_State * L, lua_TValue * func, int nresults) Wiersz 340	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaV_execute(lua_State * L, int nexeccalls) Wiersz 612	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_call(lua_State * L, lua_TValue * func, int nResults) Wiersz 402	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!f_call(lua_State * L, void * ud) Wiersz 825	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_rawrunprotected(lua_State * L, void(*)(lua_State *, void *) f, void * ud) Wiersz 127	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_pcall(lua_State * L, void(*)(lua_State *, void *) func, void * u, int old_top, int ef) Wiersz 488	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!lua_pcall(lua_State * L, int nargs, int nresults, int errfunc) Wiersz 846	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaB_pcall(lua_State * L) Wiersz 377	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_precall(lua_State * L, lua_TValue * func, int nresults) Wiersz 340	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaV_execute(lua_State * L, int nexeccalls) Wiersz 591	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_call(lua_State * L, lua_TValue * func, int nResults) Wiersz 402	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!f_call(lua_State * L, void * ud) Wiersz 825	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_rawrunprotected(lua_State * L, void(*)(lua_State *, void *) f, void * ud) Wiersz 127	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!luaD_pcall(lua_State * L, void(*)(lua_State *, void *) func, void * u, int old_top, int ef) Wiersz 488	C	Symbole zostały załadowane.
 	lua5.1c_d.dll!lua_pcall(lua_State * L, int nargs, int nresults, int errfunc) Wiersz 846	C	Symbole zostały załadowane.
 	client_d.dll!CLuaMain::PCall(lua_State * L, int nargs, int nresults, int errfunc) Wiersz 525	C++	Symbole zostały załadowane.
 	client_d.dll!CLuaArguments::Call(CLuaMain * pLuaMain, const CLuaFunctionRef & iLuaFunction, CLuaArguments * returnValues) Wiersz 218	C++	Symbole zostały załadowane.
 	client_d.dll!CMapEvent::Call(const CLuaArguments & Arguments) Wiersz 42	C++	Symbole zostały załadowane.
 	client_d.dll!CMapEventManager::Call(const char * szName, const CLuaArguments & Arguments, CClientEntity * pSource, CClientEntity * pThis) Wiersz 242	C++	Symbole zostały załadowane.
 	client_d.dll!CClientEntity::CallParentEvent(const char * szName, const CLuaArguments & Arguments, CClientEntity * pSource) Wiersz 818	C++	Symbole zostały załadowane.
 	client_d.dll!CClientEntity::CallEvent(const char * szName, const CLuaArguments & Arguments, bool bCallOnChildren) Wiersz 760	C++	Symbole zostały załadowane.
 	client_d.dll!CPacketHandler::Packet_LuaEvent(NetBitStreamInterface & bitStream) Wiersz 4992	C++	Symbole zostały załadowane.
 	client_d.dll!CPacketHandler::ProcessPacket(unsigned char ucPacketID, NetBitStreamInterface & bitStream) Wiersz 180	C++	Symbole zostały załadowane.
 	client_d.dll!CClientGame::StaticProcessPacket(unsigned char ucPacketID, NetBitStreamInterface & bitStream) Wiersz 5239	C++	Symbole zostały załadowane.
 	[Kod zewnętrzny]		Ramka z adnotacją
 	[Poniższe ramki mogą być niepoprawne i/lub brakujące, nie załadowano symboli dla netc_d.dll]		Ramka z adnotacją
 	client_d.dll!CClientGame::DoPulses2(bool bCalledFromIdle) Wiersz 1523	C++	Symbole zostały załadowane.
 	client_d.dll!CClientGame::DoPulses() Wiersz 1204	C++	Symbole zostały załadowane.
 	client_d.dll!CClientGame::DoPulsePostFrame() Wiersz 1105	C++	Symbole zostały załadowane.
 	client_d.dll!CClient::PostFrameExecutionHandler() Wiersz 221	C++	Symbole zostały załadowane.
 	core_d.dll!CModManager::DoPulsePostFrame() Wiersz 278	C++	Symbole zostały załadowane.
 	core_d.dll!CCore::DoPostFramePulse() Wiersz 1337	C++	Symbole zostały załadowane.
 	core_d.dll!CDirect3DEvents9::OnPresent(IDirect3DDevice9 * pDevice) Wiersz 137	C++	Symbole zostały załadowane.
 	core_d.dll!CProxyDirect3DDevice9::Present(const tagRECT * pSourceRect, const tagRECT * pDestRect, HWND__ * hDestWindowOverride, const _RGNDATA * pDirtyRegion) Wiersz 343	C++	Symbole zostały załadowane.
 	[Kod zewnętrzny]		Ramka z adnotacją
 	multiplayer_sa_d.dll!HOOK_CallIdle() Wiersz 61	C++	Symbole zostały załadowane.
 	[Kod zewnętrzny]		Ramka z adnotacją

FileEX avatar Sep 22 '24 21:09 FileEX

The new argument parser adds a performance overhead for arrays. I prefer to avoid using map and vector in the parser. We can add a new table generator to pass values directly into LuaVM and a table reader to get them from VM

TheNormalnij avatar Sep 23 '24 15:09 TheNormalnij

The new argument parser adds a performance overhead for arrays. I prefer to avoid using map and vector in the parser. We can add a new table generator to pass values directly into LuaVM

So what should I use as an alternative now?

FileEX avatar Sep 23 '24 15:09 FileEX

Oof, ye the server should check which vehicles can attach to trailer/tow

Fernando-A-Rocha avatar Sep 23 '24 17:09 Fernando-A-Rocha

Oof, ye the server should check which vehicles can attach to trailer/tow

???

FileEX avatar Sep 23 '24 18:09 FileEX

This crash also affects std::vector.

std::vector<std::vector<float>>

FileEX avatar Apr 25 '25 15:04 FileEX

Oof, ye the server should check which vehicles can attach to trailer/tow

???

Wtf I posted that comment in the wrong issue. Nevermind sorry.

Fernando-A-Rocha avatar Apr 26 '25 13:04 Fernando-A-Rocha

Fixed in #4180

sbx320 avatar Apr 26 '25 21:04 sbx320