Tencent / LuaPanda

lua debug and code tools for VS Code
Other
1.27k stars 355 forks source link

sol2 兼容BUG #181

Open tyler-chang opened 7 months ago

tyler-chang commented 7 months ago

我们项目中使用 sol2 3.2.3 作为绑定库. 在不使用 sol2 注册任何类型时. 调试一切正常. 当使用sol2注册一个类型: 如下代码: m_lua.new_usertype<CLogger>("CLogger", "debug_print", &CLogger::DebugPrint); 再进行调试时, 调试器就会崩溃. 提示以下错误:

CScript: sol: runtime error: sol: cannot call '__pairs/pairs' on type 'sol::as_container_t<CLogger>': it is not recognized as a container
stack traceback:
    [C]: in ?
    [C]: in function 'pairs'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:754: in function 'LuaPanda.getTableMemberNum'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:2768: in function 'LuaPanda.getGlobalVariable'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1238: in function 'LuaPanda.dataProcess'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1559: in function 'LuaPanda.receiveMessage'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1602: in function 'LuaPanda.debugger_wait_msg'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1255: in function 'LuaPanda.dataProcess'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1559: in function 'LuaPanda.receiveMessage'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1602: in function 'LuaPanda.debugger_wait_msg'
    ...
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1602: in function 'LuaPanda.debugger_wait_msg'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1151: in function 'LuaPanda.dataProcess'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1559: in function 'LuaPanda.receiveMessage'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1602: in function 'LuaPanda.debugger_wait_msg'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1151: in function 'LuaPanda.dataProcess'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1559: in function 'LuaPanda.receiveMessage'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:1602: in function 'LuaPanda.debugger_wait_msg'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:2282: in function 'LuaPanda.SendMsgWithStack'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:2216: in function 'LuaPanda.real_hook_process'
    D:\WorkSpace\April\Release\..\Public\Script\LuaPanda.lua:2073: in function 'LuaPanda.debug_hook'
    D:\WorkSpace\April\Release\..\Public\Script\launcher.lua:71: in main chunk 
Exception thrown at 0x0103CF5A in Gaze.exe: 0xC0000005: Access violation reading location 0x0000001C.

注: 崩溃不会立即发生. 在点击调试器 Global 时崩溃(如下图) image

stuartwang commented 7 months ago

我看到是 getGlobalVariable 在序列化全局变量时出错了。原因是导入的CLogger类型无法用pairs遍历。导致遍历时出错

image

这里的修复需要有接口能够判断是so2导入类型,并对导入类型进行序列化,也可以简单点处理对导入类型不做遍历操作。这个库我之前没用过,有空的时候我看一下

tyler-chang commented 7 months ago

好的, 谢谢. sol2 绑定库用的人还是蛮多的. 可以适当兼容一下.