Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


fstream lock unhandled exception - wtf?

This topic is 5553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game I have a global ofstream instance called Log which I write to for various debugging info. I''ve used this setup in multiple projects and it has worked fine. In fact, the current project is using the exact same code from my last project simply copied over as a starting point. But for some weird reason, it''s causing unhandled exception errors in this project. That in itself wouldn''t be too weird, it''s the fact that the program will happily write one or two lines to the file then decides it no longer exists (or watever it has decided is wrong) and throw exceptions. I ditched the new project and started agin, copying the files from a third project which also works fine. Again, the same error occurs. It only occurs in my current project, not in any of the other completed/abandoned projects. When the debugger stops the exception it shows this code form the ostream.cpp file:
int ostream::opfx()
    if (state)
        state |= ios::failbit;
        return 0;
    if (x_tie)
    return(1);  // return non-zero

saying that the error is on the first line (call to lock). The code I am using to open and write tot he files is the most basic code possible which I have used hundreds of times before. I simply use:
ofstream Log;
Log.open("filename.log", ios::out);


Log<<"yadda yadda";
But somehow this is dying. I checked the file and it has access permissions. I even deleted it so it would be remade. I''m at a complete loss as to what might be causing this.

Share this post

Link to post
Share on other sites
This is getting weirder. I managed to move the problem from the writing code to the checking the file is open code by moving the file open call from a standard obj.open() call to making the call via the fstream constructor.

Now it has an exception error when I call the is_good function suggesting that the global fstream variable isn''t as global as it should be. It''s as if it somehow loses the variable despite it being declared in my globals header file as:

extern ofstream Log;

and then instantiated in my main code file with:

ofstream Log("debug.log", ios::out);

Somehow the object is either being destroyed or the refernece to it is being corrupted. But the only code affecting the Log object uses either stream operators or is_open calls.

I tried the @err,hr watch and the value remains a constant S_OK.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!