Weird behavior with std::stringstream on iPhone XS
Hello, I found something very strange bug with std::stringstream on iPhone XS. I'm still putting in work to reproduce on other iPhone devices but I found it impossible to reproduce on other devices and platforms. the followings are the detailed environment.
UE4 version : 4.21.1
target device : iPhone XS
iOS version : 12.1.1
Xcode version: 10.1
The test scenario is very simple, just put these 4 lines (or maybe 3 lines) into any project and run on iPhone XS.
The problem occurs in the line that I marked, the application keeps crashing on iPhone XS, right after calling the destructor of std::string that was created temporary while copying the value into the temp_string variable.
I found someone already struggled with the same issue before and fixed in the previous versions(https://answers.unrealengine.com/questions/664905/unreal-crashes-on-two-lines-of-extremely-simple-st.html). I'm guessing this bug is related to new/delete symbols in the linker script but I have no ideas.
I confirmed that the problem can happen anytime when the std containers that are allocated by libc++ is deallocated in iOS. I doubt that this won't cause any problem in Android OS because they use libstd++ instead of libc++.
I think the bug is somewhere between allocator and deallocator. at least one of these methods is using std::allocator/deallocator instead of FMemory::Malloc() and FMemory::Free().
My team solved this problem a month ago by wrapping the std containers so they can use FMemory::Malloc() and FMemory::Free() properly. You don't need to rebuild the whole engine code.
Of course, you can see my team's code since it is opened to anyone. (https://github.com/iFunFactory/engine-plugin-ue4/commit/bc6faababee22025f5fc8b9107e855b0bc769f1e#diff-984a672cbc3814300082a9dd8e3b3c81)
My team tested it on iPhone XS and the other devices after the code is merged, No more crashes :) I assume that you can use this workaround in the production environment until the Unreal Engine(or iOS) fix this.
answered Mar 20 '19 at 02:41 PM
c_str() does not return a
answered Jan 30 '19 at 05:25 PM
I have a similar problem。 I Build a plugin as static lib use in unreal 4.2.1. have used google proto buf use xcode 9.4 and crash On the iphone A12 CPU series. like XR， XS Max Got a lot of Log : LogMemory: Warning: Attempting to free a pointer we didn't allocate! i check the code. protobuf generate .h files and include inline function use delete. it likes this delete will be use FMemory::Free() so.i add c++ flag -fno-inline-functions to rebuild lib. it's no log any more
next I Got a Crash. Dump Stack is std::basic_string::~basic_string() It's a struct member function that returns std::string definition : std::string ToString() const; implement :
it will print right log and then crash... then i test sprintf .then it works...
so ..I Guess it Should be related to the implementation of std::stringstream or Xcode stl library conflicts with A12？
Follow this question
Once you sign in you will be able to subscribe for any updates here