I have a strange problem when using ifstream and ofstream.
I made my own asset packing format today, which seemed to be working well until I use complex data in my files.
The theory is as follows;
- Drop a bunch of files on to the .exe.
- Program asks for an unsigned int ID type (i.e. 100 might be a walk sequence).
- Program packs the individual files into one along with some additional data.
- The program then does a read back of the resultant file to make sure that everything packed ok.
Does ifstream and/or ofstream have issues with complex input? Does it somehow misread some things (eg. \r \n \t \??)
I am reading and writing the files as binary, allocating memory blocks, and doing all of those sorts of things.
fsIn.open("output.txt", std::fstream::in | std::fstream::binary);
fsIn.seekg(0, std::ios::end);
int nSize = (int)fsIn.tellg();
char *memblock = new char[nSize];
fsIn.seekg(0, std::ios::beg);
fsIn.read(memblock, nSize);
fsIn.close();
This has got me stumped though.Example of dropping two text files on to the exe.
Animation sequence packing module
Files: 2
Enter sequence number: 77
0: 12
1: 11304
File Size: 22596
Read back
Objects in file: 2
12
Offset: 12
11304
Offset: 11304
(Offset: 12) ID: 77 Size: 11280
(Offset: 11304) ID: 77 Size: 11280
This is an expected result and working fine.
If I drop two binary files with (seemingly) random content the program doesn't function correctly. As per below;
Animation sequence packing module
Files: 2
Enter sequence number: 77
0: 12
1: 11304
File Size: 22644
Read back
Objects in file: 2
12
Offset: 12
11304
Offset: 11304
(Offset: 12) ID: 77 Size: 11280
(Offset: 11304) ID: 1092444195 Size: 1097630673
In this particular case the file sizes are identical to the txt files used in the previous example to rule out silly things like buffer overruns, etc.
But, the data is getting mangled at the second entry. ID: should be 77 as well and Size: should be 11280 as per the entry above.
So, this has me confused as to why this would happen, the files are being written and read in binary mode.
Probably somewhat confusing as to what I have posted here, so I am happy to share whatever you need, just point me in the right direction as to what info you are after.
I can drop any amount of text files I can find (even hundreds) and the program behaves as expected. But as soon as the data in the files becomes extremely complex the program falls over instantly (even throws 'not responding' prior to crashing)
Any help would be greatly appreciated :)