Friday, July 17, 2009

The Perils of #pragma( pack )

I just spent the last 3 hours buried in heap corruption errors, data alignment problems and a game file that seemed to compile fine but was incomprehensible by both client and server. All because I added a #pragma pack (push, 1) and followed it NOT by #pragma pack(pop) but by a seemingly innocuous variant: #pragma pack(pop, 1)

Turns out, that completely changes the behavior of the compiler directive, causing everything to become 1-byte aligned. This seriously screws up...well...just about everything. Any library not compiled with the same alignment becomes corrupted if you try to typecast virtual classes...sometimes. Random methods fail even if you know their implementation and that, just before the method is called, it has what appears to be perfectly normal data inside. And the compiler generates NOT A SINGLE WARNING about this TOTALLY INSANE behavior. GWARRAR!


Good news is Erich's meshes look amazing, and this update is nearing completion.

No comments: