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;
}
}
Cheers !