Crashes while writing to file

Started by
3 comments, last by alvaro 10 years, 8 months ago

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.

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

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( "" )
};

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.


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.

This topic is closed to new replies.

Advertisement