@kas1e
I don't recommend to hack playing with optimization level: even if it stops crashing, that would be due to a side effect.
The problem is that the structure is directly loaded from the binary file. As salass0 said, the loader have to be modified.
I thought about this solution: The idea is to access float values from the loaded binary only with byte access.
- Declare a union to manage access with float and bytes, rename the struct MS3DVertex into MS3DVertexPacked and define a struct MS3DVertex without the PACK_STRUCT keyword:
union HybridFloat {
float fvalue;
char cvalue[4];
};
struct MS3DVertexPacked
{
u8 Flags;
HybridFloat Vertex[3];
char BoneID;
u8 RefCount;
} PACK_STRUCT;
struct MS3DVertex
{
u8 Flags;
float Vertex[3];
char BoneID;
u8 RefCount;
};
- Modify the code (lines 206 to 225) by something like that (sorry, not able to compile and test here):
MS3DVertex *vertices;
MS3DVertexPacked *vertices_packed = (MS3DVertexPacked *)pPtr;
HybridFloat tmpfloat;
char *pVPtr;
pVPtr = pPtr; // address of the first packed vertex in memory
pPtr += sizeof(MS3DVertexPacked) * numVertices;
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
for (u16 tmp=0; tmp<numVertices; ++tmp)
{
#ifdef __BIG_ENDIAN__
// Read per byte with swapping and fill the 3 vertices in the final structure
// pVPtr[0] is ignored, it contains the char field Flags
tmpfloat.cvalue[3] = pVPtr[1];
tmpfloat.cvalue[2] = pVPtr[2];
tmpfloat.cvalue[1] = pVPtr[3];
tmpfloat.cvalue[0] = pVPtr[4];
vertices[tmp].Vertex[0] = tmpfloat.fvalue;
tmpfloat.cvalue[3] = pVPtr[5];
tmpfloat.cvalue[2] = pVPtr[6];
tmpfloat.cvalue[1] = pVPtr[7];
tmpfloat.cvalue[0] = pVPtr[8];
vertices[tmp].Vertex[1] = tmpfloat.fvalue;
tmpfloat.cvalue[3] = pVPtr[9];
tmpfloat.cvalue[2] = pVPtr[10];
tmpfloat.cvalue[1] = pVPtr[11];
tmpfloat.cvalue[0] = pVPtr[12];
vertices[tmp].Vertex[2] = - tmpfloat.fvalue;
// Go to the next vertex structure
pVPtr += sizeof(struct MS3DVertexPacked);
#else
vertices[tmp].Vertex[2] = -vertices[tmp].Vertex[2];
#endif
}
Additionally, about gcc options, avoid optimization options except -OX ones. And about -fexpensive-optimizations, the doc says it is activated with -O2 and stronger levels.