Streams, Universal Binary and Headaches!

BlitzMax Forums/BlitzMax Programming/Streams, Universal Binary and Headaches!

therevills(Posted 2010) [#1]
Okay, here I was building a Universal Binary for the Mac, all tested fine on the Intel but it would instantly quit on the PPC...

Hmmmm, so I install BlitzMax on the the old PPC and compile my game... error - oooookay, now we are getting somewhere....

The ReadInt of the Stream was causing the issue... removed the stream and its all good... but thats not good for the game...

Finally found it!!! Can anyone guess what the problem was? (Apart from my lack of knowledge on the subject of Streams....)


BlitzSupport(Posted 2010) [#2]
It's almost certainly due to endian-ness. You would probably fix it by changing any ReadFile calls to something like this:

Local stream:TStream = LittleEndianStream (ReadFile (f$))


... or this:

Local stream:TStream = BigEndianStream (ReadFile (f$))


I can never remember which is which, but see which one works on your existing Intel version, and it should then "just work" on your PPC version too.

Last edited 2010


*(Posted 2010) [#3]
Thanks James I forgot about that 'little quagmire' :)


Death to the Pixies!


IIRC you have had that 'sig' every since Blitz PC began :)


ima747(Posted 2010) [#4]
x86 (intel) are little endian
PPC is big endian

If there's a chance your app might be run on 2 different platforms it's a good idea to convert all your streams to the same endianness just to make sure it doesn't come back and get you later (as you've found :0). If you never have to share files between the platforms then the endianness doesn't really matter, but you just never know and it's 1 line of code... I must say I'm not great about enforcing this myself but it is worth it.

Another nice thing to look into would be catching exceptions so if your streams blow up in your face (corrupted files, god knows what someone else's hardware is going to do... or if the file gets mangled flowing through email etc.) the app doesn't follow.


BlitzSupport(Posted 2010) [#5]

Thanks James I forgot about that 'little quagmire' :)



It's really easy to deal with, though -- just pick an endian-ness and do something like the above.


... sig...



I kind of forget it's there -- I have sigs turned off!


BlitzSupport(Posted 2010) [#6]
Also, what ima747 said. There's an example here -- just look at the first function, GetBMPInfo (), for an example of handling streams, taking endian-ness into account and catching exceptions.

Also, this only applies to reading/writing files "manually" -- you don't have to worry about the built-in LoadImage, etc, functions.


therevills(Posted 2010) [#7]
Yep... it was the bloody endians!!! LOL!

Least the fix was nice and quick:

Original Code:
Local stream:TStream = ReadStream(file)


Fixed Code:
Local stream:TStream = ReadStream("littleendian::" + file)