[fixed] X mesh binary file loading on Big Endian

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Piraaate
Posts: 18
Joined: Wed Feb 21, 2007 3:04 pm
Location: Valence, France
Contact:

[fixed] X mesh binary file loading on Big Endian

Post by Piraaate »

Hi there,
I ran into another big-endian related bug when loading a binary X mesh file on a PowerPC.

Here's the fix I propose:

Code: Select all

Index: CXMeshFileLoader.cpp
===================================================================
--- CXMeshFileLoader.cpp	(revision 2415)
+++ CXMeshFileLoader.cpp	(working copy)
@@ -2259,6 +2259,9 @@
 {
 	u8 *Q = (u8 *)P;
 	u16 tmp = 0;
+#ifdef __BIG_ENDIAN__
+	*Q = os::Byteswap::byteswap(*Q);
+#endif
 	tmp = Q[0] + (Q[1] << 8);
 	P += 2;
 	return tmp;
@@ -2269,6 +2272,9 @@
 {
 	u8 *Q = (u8 *)P;
 	u32 tmp = 0;
+#ifdef __BIG_ENDIAN__
+	*Q = os::Byteswap::byteswap(*Q);
+#endif
 	tmp = Q[0] + (Q[1] << 8) + (Q[2] << 16) + (Q[3] << 24);
 	P += 4;
 	return tmp;
@@ -2316,6 +2322,10 @@
 			char tmp[8];
 			memcpy(tmp, P, 8);
 			P += 8;
+
+#ifdef __BIG_ENDIAN__
+			*(f64 *)tmp = os::Byteswap::byteswap((f32)(*(f64 *)tmp));
+#endif
 			return (f32)(*(f64 *)tmp);
 		}
 		else
@@ -2323,6 +2333,10 @@
 			char tmp[4];
 			memcpy(tmp, P, 4);
 			P += 4;
+
+#ifdef __BIG_ENDIAN__
+			*(f32 *)tmp = os::Byteswap::byteswap(*(f32 *)tmp);
+#endif
 			return *(f32 *)tmp;
 		}
 	}

Bug tracker Id: 2803647

Cheers !
ImageImage
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh yes, I guess I never tried to load a binary .x under big endian systems. It also took me a little longer to find a proper solution (I hope). Please check the 1.5 branch version under some big endian system since I don't have one right now.
Piraaate
Posts: 18
Joined: Wed Feb 21, 2007 3:04 pm
Location: Valence, France
Contact:

Post by Piraaate »

hybrid wrote:Please check the 1.5 branch version under some big endian system since I don't have one right now.
I'm currently trying to make some minimal port (I won't need/test every feature in Irrlicht) on various platforms, so be sure I'll report anything I can find :wink:
ImageImage
Post Reply