I discussed with other ppls a bit as well as doing some google, and that what i found for big-endian cpus:
1. Access with floating point registers to memory need to be either on a 4 byte boundary. The memory accesses which are not properly aligned generate an "alignment exception". If it didnt crashes on some of ppc cpus with linux , it only mean that kernel "trap" those unaligned memory accesses , and doing some realign (which is slooow). Other kernels on other oses on different big-endian cpus may throw and expections / crashes /etc.
2. PPC processors (that ones amigaos4 use) only have alignment requirements for certain types of data such as floating point.
Now, in terms of irrlicht about that ms3d loader:
1. The problem is that the structure is directly loaded from the binary file. So it have floats inside, and they not on top of structures, not aligned then, which mean they should be aligned to not crash on us.
2. I search in all the whole irrlicht 1.8.4 on PACK_STRUCT words, and found them in those ones only:
include/IAnimatedMeshMD3.h
source/Irrlicht/C3DSMeshFileLoader.h
source/Irrlicht/CAnimatedMeshHalfLife.h
source/Irrlicht/CAnimatedMeshMD3.cpp
source/Irrlicht/CImageLoaderBMP.h
source/Irrlicht/CImageLoaderDDS.h
source/Irrlicht/CImageLoaderPCX.h
source/Irrlicht/CImageLoaderPSD.h
source/Irrlicht/CImageLoaderRGB.h
source/Irrlicht/CImageLoaderTGA.h
source/Irrlicht/CImageLoaderWAL.h
source/Irrlicht/CLMTSMeshFileLoader.h
source/Irrlicht/CMD2MeshFileLoader.cpp
source/Irrlicht/CMS3DMeshFileLoader.cpp
source/Irrlicht/CMY3DHelper.h
source/Irrlicht/CMY3DMeshFileLoader.h
source/Irrlicht/COgreMeshFileLoader.h
source/Irrlicht/CTarReader.h
source/Irrlicht/CWADReader.h
source/Irrlicht/CZipReader.h
I checked all those packed structs, to find out where "floats" only used in, and so, there is really not many, there is:
source/Irrlicht/CAnimatedMeshHalfLife.h
source/Irrlicht/CAnimatedMeshMD3.cpp
source/Irrlicht/CLMTSMeshFileLoader.h
source/Irrlicht/CMD2MeshFileLoader.cpp
source/Irrlicht/CMS3DMeshFileLoader.cpp
source/Irrlicht/CMY3DHelper.h
source/Irrlicht/CMY3DMeshFileLoader.h
source/Irrlicht/CImageLoaderDDS.h :
in this one btw, we can found exactly the same kind of union code as our ppc developer give us before, its even called "endian tomfoolery"
Code: Select all
/* endian tomfoolery */
typedef union
{
f32 f;
c8 c[ 4 ];
}
floatSwapUnion;
I.e. there is already those who code that file at least know that it should be aligned (and that why they use Union as you ask before, to just made an align with float).
So, seeing on that, we can say that things which should crash on big-endian cpus are:
1. Halflife loader. That one even didn't have any big_endian ifdefs, so it wasn't care about at all , all expected.
2. MD2 loader. That one while have floats in packed structures (SMD2Frame and SMD2GLCommand), for sure didn't crashed : devs which checking that say that this loader has everything aligned. That is why it does not crash. The floats are at the top so start at 0. The other struct has a u8 at the top so the first float starts at 1 (and therefore is misaligned for the PPC FPU).
3. MD3 loader. That one not sure if ok or not, but loading a quake3 packs inside of 21.Quake3Explorer works.
4. LMTS - didn't found any test file to test with
5. MY3D - didn't found any test file to test with
In other words, its all come not to whole problem of Irrlicht, but to that single loader, which writen without keeping alignemnt in mind. So that need to be fixed/rewriten and updated in trunk for sure.
Solution there just probabaly one: Loading it as an integer and then convert it to float should work. I.e. idea is to access float values from the loaded binary only with byte access (by declare a union to manage access with float and bytes).
I.e. making something like done in CImageLoaderDDS.h :
Code: Select all
union HybridFloat {
f32 fvalue;
u8 cvalue[4];
};
And then use it in all the places in that loader in question. It will only mean a little updating of code inside of __BIG_ENDIAN__ ifdefs.
Later the same approach can be choicen when i will add big_endian ifdefs for halflifeloader.
At least, that how it alredy done in other irrlicht's parts where that necessary.