SyntaxBomb - Indie Coders
Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: Yellownakji on August 07, 2018, 20:49:59
I wrote my own file format and i can ?successfully? create a binary to read from, however, Even though i can generate a proper binary, i get a 'Invalid Bank Offset' exception.
Basically, even thought i get this error, i can still generate my binary correctly and and i don't know why it works.
--
bank = CreateBank(Size_T(StreamPos(stream))) 'Create a bank with the same size as the stream we wrote to
** I use streampos because it results the same as streamsize. i wrote the data first so the last pos is = to the size..
ReadBank(bank, stream, Size_T(Banksize(bank)), StreamPos(stream)) 'Write the stream to the bank
SaveBank(bank, String(container)) 'Finalize the bank to a physical binary
--
Now of course, the issue may be obvious... Arg3 in Readbank is 'Size_T(Banksize(bank))' when it should be an offset. Okay..?
My issue is that even though this is most likely incorrect, i can still generate a perfectly working binary to read from. Everything is in the correct order.. correct size etc etc. My custom file's contents are just how they should be. ....but i get an 'Invalid Bank Offset' exception? Why does this still work? Everything still get's written after the application terminates.
I really don't get it. What am i supposed to do for offset?
QuoteWhat am i supposed to do for offset?
0 ( zero ) to start reading from the stream to the beginning of the bank?
I think you may need to reset the position pointer for the stream too as ReadBank will start to read from the current stream position for Arg4 ( count ) number of bytes. You'll need to store the size of the stream in order to do that correctly if you have already 'read' from it.
' streamsize:Size_T = Size_T(StreamPos(stream)) ' Using your method or preferably...
streamsize:Size_T = StreamSize(stream)
SeekStream(stream, 0)
bank = CreateBank(streamsize) 'Create a bank with the same size as the stream we wrote to
ReadBank(bank, stream, 0, streamsize) 'Write the stream to the bank
SaveBank(bank, String(container)) 'Finalize the bank to a physical binary
Thank you so much, Col! You're such a big help, once again.
I've never worked with binary... been itching to learn for a long time and write my own format. Thank you!!