I'm getting a strange exception when using Cocoa together with a personal C++ library, while the exception only occurs in debug mode - in release mode everything is fine. And to stress that, it suffices to link my C++ library to get the exception, I don't need to call my library at all.
The error I get is "Exception: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)".
The C++ library is built using CMake and the mode is determined by the internal "CMAKE_BUILD_TYPE". The library can be found on GitHub, though I don't think that anyone wants to build it. Also because it is quite huge, I don't think that someone wants to look at the code.
A very minimal example to demonstrate the error is the following one:
#include <Cocoa/Cocoa.h>
int main()
{
[NSApplication sharedApplication];
printf("success\n");
return 0;
}
As you can see, this example does not use my lib at all.
I don't understand it. What could I possible have done in my library that crashes Cocoa just because I link to it? The only thing that could come to my mind is that I have defined my own global operator new and delete. Still, Cocoa wouldn't use those, right?
Here is the full stack trace:
(anonymous namespace)::get_registry() (.8898) 0x00007fff564afd79
SLSNewConnection 0x00007fff56473dc4
SLSMainConnectionID 0x00007fff56474a87
_CFAppSleepSetupCoreGraphics 0x00007fff34649091
____CFRunLoopSetOptionsReason_block_invoke_2 0x00007fff34648738
_dispatch_client_callout 0x00007fff5c43ddb8
dispatch_once_f 0x00007fff5c43dd6b
__CFRunLoopSetOptionsReason 0x00007fff34646ff3
_LSApplicationCheckIn 0x00007fff35ae7abb
_RegisterApplication 0x00007fff32ec192c
GetCurrentProcess 0x00007fff32ec064c
MenuBarInstance::GetAggregateUIMode(unsigned int*, unsigned int*) 0x00007fff3391e4ab
MenuBarInstance::IsVisible() 0x00007fff3391e435
_NSInitializeAppContext 0x00007fff31bc1197
-[NSApplication init] 0x00007fff31bc0590
+[NSApplication sharedApplication] 0x00007fff31bc01e6
main main.mm:5
start 0x00007fff5c477015
start 0x00007fff5c477015
Thanks for any help in advance!
Indeed @Kai Guther was correct. Cocoa was using my overridden global new. Apparently I had a bug in my replaced new operator. After a bit of refactoring of that function, it works now. Thanks for the important information... I think without that guess I would've searched for ages for that terrible bug...