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)  

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: = "levelOne";"level1.lvl"), ofFile::WriteOnly, true);  
file.write((char*)&newLevel, sizeof(newLevel));  
file.close();"level1.lvl", ofFile::ReadOnly, true);*)&newLevel2, sizeof(file));  

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,

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.