Nambers / MiraiCP

c++ SDK of Mirai
https://eritque-arcus.tech/MiraiCP/
GNU Affero General Public License v3.0
176 stars 31 forks source link

插件的部分全局变量无法正常构造 #126

Closed Antares0982 closed 2 years ago

Antares0982 commented 2 years ago

Code of Conduct

问题描述

插件在被调用libOpen()时,初始化所有全局变量。如果存在MiraiCP提供的部分类的对象(如Member),构造函数调用时会尝试call一次ktOperation,此时loader api未设置,在进行checkApi时会出现段错误。

LibLoader::LoaderApi::pluginOperation loaderApi.cpp:56    <---------------------
MiraiCP::KtOperation::ktOperation KtOperation.cpp:28
MiraiCP::LowLevelAPI::getInfoSource LowLevelAPI.cpp:48
MiraiCP::Member::refreshInfo Member.cpp:37
MiraiCP::Member::Member Member.cpp:31    <---------------------
__static_initialization_and_destruction_0 main.cpp:119
_GLOBAL__sub_I_main.cpp(void) main.cpp:1105
<unknown> 0x00007f7a7d19ecee
<unknown> 0x00007f7a7d19eddc
_dl_catch_exception 0x00007f7a7d091da4
<unknown> 0x00007f7a7d1a5557
_dl_catch_exception 0x00007f7a7d091d4e
<unknown> 0x00007f7a7d1a58ed
<unknown> 0x00007f7a7cfc486c
_dl_catch_exception 0x00007f7a7d091d4e
_dl_catch_error 0x00007f7a7d091e03
<unknown> 0x00007f7a7cfc433f
dlopen 0x00007f7a7cfc4921    <---------------------
LibLoader::LoaderApi::libOpen libOpen.h:45
LibLoader::load_plugin PluginListImplements.cpp:146
LibLoader::loadsAll PluginListImplements.cpp:237
LibLoader::registerAllPlugin PluginListImplements.cpp:265
Verify ktInterface.cpp:54
...

预期行为:Member构造时不应抛出任何异常

可能的解决方案:Member等的构造改为lazy construct

日志

No response

版本

v2.12.0-RC

组件

Plugin

Antares0982 commented 2 years ago

dev分支经测试已经解决该问题