Error at program close

So, I always get an “Access Violation” (0xC0000005) error when exiting my program.

When exiting with the escape key, Visual Studio points me to this codesection in xlock.cpp, line 64:

  
  
__thiscall _Lockit::_Lockit(int kind)  
	: _Locktype(kind)  
	{	// lock the mutex  
	if (_Locktype < MAX_LOCK)  
		_Mtxlock(&mtx[_Locktype]);  
	}  
  

When exiting via the close button, it stops the program in the ofAppGlutWindow.cpp file at the end of the runAppViaInfiniteLoop function.

My program doesn’t do much, it’s basicly just this code in the setup function:

  
  
newLevel.name = "levelOne";  
  
file.open(ofToDataPath("level1.lvl"), ofFile::WriteOnly, true);  
if(!file.exists()){  
	file.create();  
}  
file.write((char*)&newLevel, sizeof(newLevel));  
file.close();  
	  
file2.open("level1.lvl", ofFile::ReadOnly, true);  
file2.read((char*)&newLevel2, sizeof(file));  
file2.close();  
  

And here is the level struct I’m using:

  
  
struct level {  
	string name;  
};  
  

So, I don’t really understand why this error occurs because my actual code section works fine, it reads and writes the data just as I want it to.

Is there something I’m doing wrong on using the ofFile object? I was just experimenting with file operations, so I’m fairly new.

Thanks in advance,
Xera.

Oh well, I found a better solution to my problem and the bug doesn’t occur anymore.
If anybody still has a solution, feel free to post them anyway.