The EntityAppearance class implements the different entity appearances as structs stored in a union, assigns to an integer member of the union when reading over the network, and then offers functions to read the union as differing structs with bitfields for the relevant appearance values.
This use of a union is undefined behaviour in C++, violating the strict type aliasing rule. Well, probably, the standard doesn't leave it very clear and some compilers appear to document that specific behaviour as a bad idea. See https://blog.regehr.org/archives/959 for a discussion of the strict type aliasing rule and https://msdn.microsoft.com/en-us/library/5dxy4b7b.aspx for Visual Studio 2015 documentation that notes that "Unions can be useful for conserving memory when you have lots of objects and/or limited memory. However they require extra care to use correctly because you are responsible for ensuring that you always access the last member that was written to.". The documentation for Visual Studio 2008 was more explicit: https://msdn.microsoft.com/en-us/library/5dxy4b7b%28v=vs.90%29.aspx contains a comment "We recommend that you do not use a union to cast data from one data type to another because union members occupy the same address in memory.
There is no data-conversion support for unions. The results of interchanging writes and reads between union members of different types are unpredictable and depend on a variety of reasons. "
Anonymous
Resolved by merge 23