C++ binary files

Started by
4 comments, last by THACO 18 years, 9 months ago
Ok, so I export my mesh from 3dsmax through my own exporter, then I want to convert it a little and combine it with other files to create my level file. Right now I am just putting together the geometry in an easy to read in fashion for the engine. I had it working, well I thought I did, then I decided to try to make triangle strips, did some work, then decided against it. Now when I removed that code for the strips I can only write to a file if I use the debugger (F5, not ctrl F5). If I use F5 it works fine, if I run it using ctrl +F5 it will not write to the file and crashes as soon as I try to write anything to the outfile. here is a snippet of code

outFile = fopen(outfname.c_str(), "wb");
	if(!outFile)
	{
		cout<<"ERR opening output file"<<endl;
		return 0;
	}
	else
		cout<<"OUTPUT FILE OPENED"<<endl;

//later in code  or anything else I try to write to the file
      char end[12];
	sprintf(end,"ENDTRIS");
	fwrite(end,sizeof(char[12]),1,outFile);

Any ideas? -THACO
Advertisement
Weird...

Probably if you provide information about the crash people might be able to help you more (where are you crashing, what is the message?)

BTW-
The lines:
sprintf(end,"ENDTRIS");
fwrite(end,sizeof(char[12]),1,outFile);

You can change the sizeof(char[12]) for sizeof(end), that way if you change end to be more of less characters the code will still work; also make sure you have the second and third parameter of fwrite right (one is count and the other is size but I do not remember which is which)
I'm going to guess that you've got a buffer overflow in your code somewhere between opening the file and writing to it.
Perhaps it's because of the null termination of the string in debug mode and not in release mode. Try:
char end[12] = {0};sprintf(end,"ENDTRIS");fwrite(end,sizeof(char[12]),1,outFile);
Combiner.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

then the whole
"If you were in the middle of something, the information you were working on might be lost.

Please tell Microsoft about this problem
We have created an error report that you can send to us. We will treat this report as confidential and anonymouse


DEBUG SEND ERROR REPORT DON"T SEND
"

It is one of those errors.


cout<<"test3"<<endl;
return 0;
}

above is the last 3 lines of my code, it will write test3 to the screen, then hang for a second and give me the same error as before. I moved the write to file stuff up to top of code and it does write to the file. I think I might just have to create a new project, at least I can clean up my code that way. Still have no idea what the heck is goin on

-THACO
Well not sure if I really fixed it but for those who care, I think that when I was reading in some information I caused the problem, but it didn't crash until I tried to write something. I realized I was not reading in the data properly, I somehow screwed up my own file format, but that might have been the case. Eitherway I started a whole new solution/project and it seems to be working. Thanks for all the input

-THACO

This topic is closed to new replies.

Advertisement