Crashes on thread exit in shared library built with libc++

When an external shared library’s thread exits, it crashes the engine with a signal 11 error from Fmalloc. But only if that library was compiled with libc++, ones made with libstdc++ are fine. Which would fix my problem, except that beacause UE uses libc++, in order for any function that takes a string as an input (or a vector or any other standard type) to be callable, the other library has to be compiled with libc++.
The library works fine on it’s own - it’s something about how it connects to UE that causes the issue.

Full instructions and code to reproduce this is at GitHub - thesilencelies/UEThreadBugMWE: Minimum files to demonstrate the bug where unreal engine crashes on exit from a third party library thread.

Any ideas of a fix/workaround?

thanks

Your question actually turns out to be my answer. Linking libc++ instead of libstdc++ actually avoid segfault for me and it’s running smoothly. I was having a hard time integrating third-party library on linux until I read this post. Thanks for the help although I didn’t know the exact answer you have. It maybe helpful for others who is having problems.

This is what I used for

-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_FLAGS=“-std=c++11 -stdlib=libc++ -I/usr/include/libcxxabi”

The idea behind is to compiles using libc++ not libstdc++ depends on your third party library. In my case was AWS SDK.

Glad to hear this helped. I haven’t actually got a fix for this: the nature of my project has changed slightly so the code that this was relevant for wasn’t needed any more. May I ask where your segfault was?

Any news in this field? I have a simillar problem. I’m writing a static library for iOS and when I’m building and linking it with libstdc++ everything works fine, but when with libc++ I have crashes in std::strings and std::vectors, in really strange places.

libstdc++ is currently deprecated on iOS, so I don’t want to use it, but at this moment I have no choice :frowning:

When I’m running my library with iOS app it works fine, but strange things happens after linking it to the engine.

What’s more - crashes occurs only on shipping builds. Development builds works fine (but it is probably because of less restricted memory management).

Any clues what can be wrong with it?

Same here, I am having segfaults in the destructors of std::string and std::future on an externally linked library

I’m getting exact same issue. The thread exit in library causes segfault. I’m also seeing segfaults in strange places such as fstream and stringstream. It would be great if Unreal folks can specify the best way to compile libraries that works with their engine.

This probably won’t help. but I noticed that using different libraries to support threads is usually a bad idea which can lead to crashes.

This is why I’m using WinAPI threads for Windows and pthread for other unix related platforms in my own sdk.

I am using windows Visual Studio Community 2017 ver.15.7.6 + UE 4.19.2.
One of my .dll work fine outside UE; However while it is used in UE project as plugin, it crashes every time in destruction of std::thread, which is very, very despairing.
Is there any way to fix this?

1 Like