I have an issue where I get a crash when starting a custom-built timer for my game, but only in release mode. After thinking about it more, I believe I know what the problem is, but I want to check here to make sure.
My timer stores its callback in a std::function object. Whenever a timer is created and started, it adds itself to a global list of timers that run every iteration of the game loop. The global timers list is initialized with the memory allocated by the platform layer, and allocates its nodes using a pool allocation strategy. The crash happens when the copy-assignment operator is executed when assigning the timer object to the data of the list node. I get a EXC_BAD_ACCESS (GPFLT) exception, which indicates some kind of error with the memory I'm operating with.
Since the timer object is created in the game (DLL) layer (as a local variable) and then copied into the global timers list (which was initialized with the memory allocated by the platform layer), my suspicion is that the exception is happening because it can't copy executable code across module boundaries. Either that, or std::function can't reference executable code across a module boundary. This either isn't happening, or isn't checked when in debug mode. That's the only thing I can think of that is causing this crash. Does that make sense?
If that is indeed the problem, is there a solution to this? If I don't allocate the global timers list with the memory from the platform layer (and just use malloc for every node), everything works fine. But that means the timers won't be serialized with the rest of the game memory.