Hi there,
I’m throwing a bottle at the sea about an issue that’s been blocking us for a few days.
A crash when loading textures
We’re developing the MacOS version of a tool that uses the C SDK. It’s nearly ready for release but we’re suffering from crashes when loading a texture.
This happens when calling SUImageRepLoadFile
(same thing happens with SUTextureCreateFromFile
). Here’s some debug code with a stack trace that ends in the FreeImage_Validate
function.
Given the EXC_BAD_ACCESS and the semi-random nature of the crash (happens ~ half the time), we suspected that we’re suffering from undefined behaviours due to some unholy memory usage from our side.
However, the last few days we tried the following steps, to no avail:
- Reduced the code to a minimum (removed any parallelism and only left the essential parts).
- Used some analysis tools (XCode static analysis + runtime instrumentation tools) to check for undefined behaviours & invalid memory usage but there seems to be nothing wrong on that side.
Also, this tool has had a Windows version for 10 months with no such issues.
So maybe the crash comes from elsewhere?
libstdc++ vs libc++
The SDL documentation does mention that:
SketchUp 2017 for OS X is built using libstdc++, so plugins should be built with the same library. Using libc++ will likely cause the plugin to fail to load and cause SketchUp to crash."
Since we’re using XCode 11, we use libc++. One important detail is that our tool is a standalone application that uses the SketchUp SDK, not a plugin. However, at this point, the difference in C++ library seems worth investigating.
XCode does allow to switch to a deprecated version of libstdc++ but it does not support C++11 and later. This is a big issue for us as we have a lot of code that uses modern features of the language. Even if we instead used Boost to support some of those features, we have third-party dependencies that need C++11 and that do not allow that.
My setup:
- MacOS Catalina 10.15.1
- Xcode 11.2.1 (also tried with 11.1.0)
- SketchUP SDK 2019
In summary
- Has anyone experienced a similar issue, EXC_BAD_ACCESS, when manipulating textures?
- Any thoughts about libc++/libstdc++ on MacOS when developing a standalone application?
I’ll continue fiddling with our code to look for bad stuff on our side, but in the meantime any insights about those two points could be very precious!
Thanks