GarageGames / Torque3D

MIT Licensed Open Source version of Torque 3D from GarageGames
http://torque3d.org
MIT License
3.35k stars 1.2k forks source link

Global Intern'd Strings do not free correctly on quit #713

Open jamesu opened 10 years ago

jamesu commented 10 years ago

In a release build on OSX, (xcode 5.1.1), when global intern'd string (such as the GFX Semantics) is released upon shutdown memory corruption can occur. Specifically it seems the associated StringData is corrupted leading to a crash. This may propagate to other systems creating odd behaviour in random locations.

Adding a check such as follows seems to "fix" the problem

String::~String()
{
   if (!_string->isInterned())
      _string->release();
}

I'm still not too sure why this problem is occurring in the first place since adding watchpoints on the relevant memory addresses seems to indicate nothing is amiss, although I find it a little odd that the engine is creating a whole bunch of objects with allocated memory before the engine is initialized.

crabmusket commented 10 years ago

Huh. Were you asking about this on IRC today? I'm going to guess that unit tests would not necessarily cover this since we're talking about globals? (I don't actually know how interned strings work. Time to do some research.) Thinking in the context of this sort of thing (automated memory leak checks) which I am pushing to get included in stock T3D unit testing when we move to gtest.

Just wanted to say thanks for all these reports! I wish we were quicker at responding to them - you just report very daunting-sounding issues :P.

jamesu commented 10 years ago

Yeah, it also seems this may be related to linker order, or it could be that OSX deals with shared library's differently when terminating. This bug seems to have started cropping up when we moved to a single .app build on OSX.