ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 492 forks source link

std::terminate called on attempting to index a nil value #1580

Closed cppimprov closed 4 months ago

cppimprov commented 4 months ago

The following code causes std::terminate to be called:

int main() {

    sol::state lua;

    try
    {
        lua["a"]["b"] = 5;
    }
    catch (std::exception& e)
    {
        std::cout << "Lua error: " << e.what() << std::endl;
    }

}

This seems to be caused (most directly - I'm not sure if there's more to it) by the ~push_popper_n destructor trying to do cleanup and causing a second error, and hence a second exception. The call stack looks like this:

sol_test.exe!issue_debug_notification(const wchar_t * const message) Line 28 (c:\Program Files\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp:28)
sol_test.exe!__acrt_report_runtime_error(const wchar_t * message) Line 154 (c:\Program Files\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp:154)
sol_test.exe!abort() Line 61 (c:\Program Files\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:61)
sol_test.exe!terminate() Line 59 (c:\Program Files\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\misc\terminate.cpp:59)
sol_test.exe!FindHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, unsigned char recursive, int CatchDepth, unsigned __int64 * pMarkerRN) Line 823 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:823)
sol_test.exe!__InternalCxxFrameHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 397 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:397)
sol_test.exe!__InternalCxxFrameHandlerWrapper<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 234 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:234)
sol_test.exe!__CxxFrameHandler4(EHExceptionRecord * pExcept, unsigned __int64 RN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC) Line 304 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:304)
ntdll.dll!00007ffbb1d723af() (Unknown Source:0)
ntdll.dll!00007ffbb1d214b4() (Unknown Source:0)
ntdll.dll!00007ffbb1d70ebe() (Unknown Source:0)
KernelBase.dll!00007ffbaf6ccf19() (Unknown Source:0)
sol_test.exe!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 75 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\throw.cpp:75)
sol_test.exe!sol::default_at_panic(lua_State * L) Line 68 (d:\Projects\CppImp\rog3\Code\sol\sol\state_handling.hpp:68)
sol_test.exe!luaD_throw(lua_State * L, int errcode) Line 132 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:132)
sol_test.exe!luaG_errormsg(lua_State * L) Line 819 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:819)
sol_test.exe!luaG_runerror(lua_State * L, const char * fmt, ...) Line 836 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:836)
sol_test.exe!typeerror(lua_State * L, const TValue * o, const char * op, const char * extra) Line 729 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:729)
sol_test.exe!luaG_callerror(lua_State * L, const TValue * o) Line 752 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:752)
sol_test.exe!luaD_tryfuncTM(lua_State * L, StackValue * func) Line 419 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:419)
sol_test.exe!luaD_precall(lua_State * L, StackValue * func, int nresults) Line 612 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:612)
sol_test.exe!ccall(lua_State * L, StackValue * func, int nResults, unsigned int inc) Line 635 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:635)
sol_test.exe!luaD_callnoyield(lua_State * L, StackValue * func, int nResults) Line 656 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:656)
sol_test.exe!callclosemethod(lua_State * L, TValue * obj, TValue * err, int yy) Line 118 (d:\Projects\CppImp\rog3\Code\lua\src\lfunc.c:118)
sol_test.exe!prepcallclosemth(lua_State * L, StackValue * level, int status, int yy) Line 153 (d:\Projects\CppImp\rog3\Code\lua\src\lfunc.c:153)
sol_test.exe!luaF_close(lua_State * L, StackValue * level, int status, int yy) Line 234 (d:\Projects\CppImp\rog3\Code\lua\src\lfunc.c:234)
sol_test.exe!lua_settop(lua_State * L, int idx) Line 202 (d:\Projects\CppImp\rog3\Code\lua\src\lapi.c:202)
sol_test.exe!sol::stack::push_popper_n<0>::~push_popper_n<0>() Line 89 (d:\Projects\CppImp\rog3\Code\sol\sol\reference.hpp:89)
sol_test.exe!`sol::basic_table_core<1,sol::basic_reference<0>>::traverse_set<char const (&)[12],char const (&)[9],int>'::`1'::dtor$1() (Unknown Source:0)
sol_test.exe!_CallSettingFrame() Line 50 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\amd64\handlers.asm:50)
sol_test.exe!__FrameHandler4::FrameUnwindToState(unsigned __int64 * pRN, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int targetState) Line 1146 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:1146)
sol_test.exe!__FrameHandler4::FrameUnwindToEmptyState(unsigned __int64 * pRN, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo) Line 234 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:234)
sol_test.exe!__InternalCxxFrameHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 354 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:354)
sol_test.exe!__InternalCxxFrameHandlerWrapper<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 234 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:234)
sol_test.exe!__CxxFrameHandler4(EHExceptionRecord * pExcept, unsigned __int64 RN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC) Line 304 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:304)
ntdll.dll!00007ffbb1d7242f() (Unknown Source:0)
ntdll.dll!00007ffbb1d00939() (Unknown Source:0)
sol_test.exe!__FrameHandler4::UnwindNestedFrames(unsigned __int64 * pFrame, EHExceptionRecord * pExcept, _CONTEXT * pContext, unsigned __int64 * pEstablisher, void * Handler, FH4::FuncInfo4 * __formal, int TargetUnwindState, int CatchState, FH4::HandlerType4 * pCatch, _xDISPATCHER_CONTEXT * pDC, unsigned char recursive) Line 685 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:685)
sol_test.exe!CatchIt<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, FH4::HandlerType4 * pCatch, const _s_CatchableType * pConv, FH4::TryBlockMapEntry4 * pEntry, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char IsRethrow, unsigned char recursive) Line 1370 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:1370)
sol_test.exe!FindHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, unsigned char recursive, int CatchDepth, unsigned __int64 * pMarkerRN) Line 679 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:679)
sol_test.exe!__InternalCxxFrameHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 397 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:397)
sol_test.exe!__InternalCxxFrameHandlerWrapper<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 234 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:234)
sol_test.exe!__CxxFrameHandler4(EHExceptionRecord * pExcept, unsigned __int64 RN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC) Line 304 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:304)
ntdll.dll!00007ffbb1d723af() (Unknown Source:0)
ntdll.dll!00007ffbb1d214b4() (Unknown Source:0)
ntdll.dll!00007ffbb1d70ebe() (Unknown Source:0)
KernelBase.dll!00007ffbaf6ccf19() (Unknown Source:0)
sol_test.exe!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 75 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\throw.cpp:75)
sol_test.exe!sol::default_at_panic(lua_State * L) Line 68 (d:\Projects\CppImp\rog3\Code\sol\sol\state_handling.hpp:68)
sol_test.exe!luaD_throw(lua_State * L, int errcode) Line 132 (d:\Projects\CppImp\rog3\Code\lua\src\ldo.c:132)
sol_test.exe!luaG_errormsg(lua_State * L) Line 819 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:819)
sol_test.exe!luaG_runerror(lua_State * L, const char * fmt, ...) Line 836 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:836)
sol_test.exe!typeerror(lua_State * L, const TValue * o, const char * op, const char * extra) Line 729 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:729)
sol_test.exe!luaG_typeerror(lua_State * L, const TValue * o, const char * op) Line 738 (d:\Projects\CppImp\rog3\Code\lua\src\ldebug.c:738)
sol_test.exe!luaV_finishset(lua_State * L, const TValue * t, TValue * key, TValue * val, const TValue * slot) Line 353 (d:\Projects\CppImp\rog3\Code\lua\src\lvm.c:353)
sol_test.exe!auxsetstr(lua_State * L, const TValue * t, const char * k) Line 841 (d:\Projects\CppImp\rog3\Code\lua\src\lapi.c:841)
sol_test.exe!lua_setfield(lua_State * L, int idx, const char * k) Line 874 (d:\Projects\CppImp\rog3\Code\lua\src\lapi.c:874)
sol_test.exe!sol::stack::field_setter<char [9],0,0,void>::set<char const (&)[9],int>(lua_State * L, const char[9] & key, int && value, int tableindex) Line 238 (d:\Projects\CppImp\rog3\Code\sol\sol\stack_field.hpp:238)
sol_test.exe!sol::stack::set_field<0,0,char const (&)[9],int>(lua_State * L, const char[9] & key, int && value, int tableindex) Line 1251 (d:\Projects\CppImp\rog3\Code\sol\sol\stack_core.hpp:1251)
sol_test.exe!sol::basic_table_core<1,sol::basic_reference<0>>::traverse_set_deep<0,0,0,char const (&)[9],int>(int table_index, const char[9] & key, int && <keys_0>) Line 295 (d:\Projects\CppImp\rog3\Code\sol\sol\table_core.hpp:295)
sol_test.exe!sol::basic_table_core<1,sol::basic_reference<0>>::traverse_set_deep<1,0,0,char const (&)[12],char const (&)[9],int>(int table_index, const char[12] & key, const char[9] & <keys_0>, int && <keys_1>) Line 295 (d:\Projects\CppImp\rog3\Code\sol\sol\table_core.hpp:295)
sol_test.exe!sol::basic_table_core<1,sol::basic_reference<0>>::traverse_set<char const (&)[12],char const (&)[9],int>(const char[12] & <keys_0>, const char[9] & <keys_1>, int && <keys_2>) Line 463 (d:\Projects\CppImp\rog3\Code\sol\sol\table_core.hpp:463)
sol_test.exe!sol::table_proxy<sol::basic_table_core<1,sol::basic_reference<0>> &,std::tuple<char const (&)[12],char const (&)[9]>>::tuple_set<0,1,int>(std::integer_sequence<unsigned __int64,0,1> __formal, int && value) Line 57 (d:\Projects\CppImp\rog3\Code\sol\sol\table_proxy.hpp:57)
sol_test.exe!sol::table_proxy<sol::basic_table_core<1,sol::basic_reference<0>> &,std::tuple<char const (&)[12],char const (&)[9]>>::set<int>(int && item) Line 89 (d:\Projects\CppImp\rog3\Code\sol\sol\table_proxy.hpp:89)
sol_test.exe!sol::table_proxy<sol::basic_table_core<1,sol::basic_reference<0>> &,std::tuple<char const (&)[12],char const (&)[9]>>::operator=<int>(int && other) Line 124 (d:\Projects\CppImp\rog3\Code\sol\sol\table_proxy.hpp:124)
sol_test.exe!main() Line 52 (d:\Projects\CppImp\rog3\Code\sol_test\main.cpp:52)
sol_test.exe!invoke_main() Line 79 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
sol_test.exe!__scrt_common_main_seh() Line 288 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
sol_test.exe!__scrt_common_main() Line 331 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
sol_test.exe!mainCRTStartup(void * __formal) Line 17 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
kernel32.dll!00007ffbb1a07344() (Unknown Source:0)
ntdll.dll!00007ffbb1d226b1() (Unknown Source:0)
Rochet2 commented 4 months ago

This is related: https://github.com/ThePhD/sol2/issues/705#issuecomment-437588145 While not necessarily a duplicate ticket, the issue is probably ultimately the same.

cppimprov commented 4 months ago

Yep. That looks like it.