Jump to content

  • Log In with Google      Sign In   
  • Create Account


Crashes while writing to file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Noxil   Members   -  Reputation: 569

Like
0Likes
Like

Posted 01 August 2013 - 04:51 AM

Hello

 

The problem im having is that the program crashes while writing to a file.

I have made a tool that generates code during the pre build step.

 

The code doing the writing looks like this:

#define WRITE_LINE( x ) file << x << "\n";

std::ofstream file( "GenClass.cpp" );
...
WRITE_LINE( "some text" << someVariable << "some more text" )
WRITE_LINE( "long line of text" )

The code is very simple.
And at the current state it dosnt write that much either.
It writes about 1000 lines of code.

 

It crashes when it tries to write regular text just like the second example of WRITE_LINE.

If for example the text im trying to write at the point of the crash is "void TestFunction()".

It only writes "void Tes".

If i change the text to "//void TestFunction()".

It only writes "//void T".

 

So it feels like it maxes out some sort of buffer.

Never run into this before, so not quite sure what to do.



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 12844

Like
1Likes
Like

Posted 01 August 2013 - 05:42 AM

Can you try to boil down your program to the smallest possible program that still shows the problem, and then post it?

Edited by Álvaro, 01 August 2013 - 05:42 AM.


#3 Noxil   Members   -  Reputation: 569

Like
0Likes
Like

Posted 01 August 2013 - 05:51 AM

That will be really hard but ill give it a try.

 

I also utilize lambdas like this if it can affect the stream somehow:

auto WriteSectionComment = [&file]( const std::string & _Title )
{
WRITE_LINE( "/////////////////////////////////////////////////" )
WRITE_LINE( "// " << _Title )
WRITE_LINE( "/////////////////////////////////////////////////" )
WRITE_LINE( "" )
};


#4 Noxil   Members   -  Reputation: 569

Like
1Likes
Like

Posted 01 August 2013 - 06:34 AM

Ah dang, thanks for the reply.
While i was trying to break it down it just poped out.

 

I forgot to check for a null pointer.

Damn... Been looking over the code so many times and overlooked it every single time.

 

Thanks! smile.png
It now works properly.


Edited by Noxil, 01 August 2013 - 06:35 AM.


#5 Álvaro   Crossbones+   -  Reputation: 12844

Like
2Likes
Like

Posted 01 August 2013 - 08:09 AM


Ah dang, thanks for the reply.
While i was trying to break it down it just poped out.

 

Actually, that's what usually happens when trying to simplify a buggy program into the minimal program that shows the bug. And if it doesn't pop up, you can always take the result and post it on a forum, with much better chances of getting relevant help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS