查了很久,终于定位到这个坑爹错误了。
UE5 的使用的标准是 C++17
我的DLL使用的标准是 C++20。接口使用了 vector<uint8_t> 类用来数据交互。
如以下代码
环境是 C++17
::GetCurImage 为C++20写的DLL的函数,在语句 return true 后,tmp_image_data 变量进行释放,破坏了内存,导致UE5直接闪退。
报错是析构 tmp_image_data 时出现了空指针异常。
bool UMyMsgPipeLib::ThisGetCurImage(FString address, int port, int timeout_sec, TArray<uint8>& image_data)
{
vector<uint8_t> tmp_image_data;
bool r = ::GetCurImage(to_string(address), port, timeout_sec, tmp_image_data);
bool r = false;
if (!r)
{
return false;
}
image_data.Empty(tmp_image_data.size());
image_data.Append(tmp_image_data.data(), tmp_image_data.size());
return true;
}
文章描述了一个UE5项目在调用C++20标准编译的DLL时遇到的问题。由于DLL使用了C++20的特性,特别是vector<uint8_t>,在返回值处理中发生了内存破坏,导致UE5在析构对象时遇到空指针异常并闪退。问题出在DLL中的内存管理与UE5的预期不一致。
4万+

被折叠的 条评论
为什么被折叠?



