Crash when freeing memory.
I'm having a problem when I try to free memory. I have my own struct to store info, its called SoundNode, and I have an STL vector to store all the SoundNodes in the scene, here is the code:
Code:
std::vector<SoundNode *> SceneNodes;
Now in the destructor of my scene manager I call a function called freeMemory() that frees all the memory allocated before (I don't put the code in the actual destructor because in some cases I want to free the memory of the scene manager without actually destroying the object). Now my freeMemory() function looks like this:
Code:
void SceneManager::freeMemory()
{
for(int i = 0; i < (int)SceneNodes.size(); ++i)
{
if(SceneNodes[i])
delete SceneNodes[i];
SceneNodes[i] = NULL;
}
SceneNodes.clear();
}
Now, when I run this in debug mode inside Visual Studio 2003 everything works fine. But if I run the same executable outside Visual Studio the application crashes when I try to delete SceneNodes[i]. Any idea what's wrong with my code?
Thanks in advance.