Corrupted graphics, misplaced objects
Closed this issue · 6 comments
I'm using Visual Studio 2019, SDL2-2.0.14 (https://www.libsdl.org/release/SDL2-devel-2.0.14-VC.zip), and I have commit 5650a16 checked out.
I run the following command to build the solution:
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBACKEND=SDL2 -DMSVC_LINK_STATIC_RUNTIME=ON -DSDL2_DIR=[path]\SDL2-2.0.14
I then open the .sln file in VS2019, build (x64, Debug or Release made no difference) and run. The graphics are corrupted as shown.
In the third screenshot, Sonic is standing on solid terrain. The bridge next to him works if he stands on it, but it's not over a gap as intended.
I have no idea what the hell happened here? I've only ever compiled using GCC, but I hadn't imagined that MSVC would somehow screw it up this bad.
To add on, I believe I can see the specific issues here. Object mappings aren't being applied properly, which is why all objects with more than 1 sprite piece (Sonic, Title Sonic, etc.) are kind of garbled. Planes just aren't referencing the correct data. However, the misplaced objects? No idea. The only way things can be this screwed up is if MSVC manages to fail to compile basic bitwise operations.
I got mingw-w64 installed and built SoniCPort with it, and it works, so this is definitely specific to MSVC.
While I don't have any specific knowledge of what's wrong here, usually when this sort of thing happens, it's a sign that you might be running into Undefined Behavior, i.e. something that's semantically invalid in C, or you're managing memory wrong, or maybe there's an uninitialized variable somewhere, etc. This all tends to cause code to miscompile especially when optimizations are turned on.
One way to test would be to try a Debug build (or otherwise a build with -O0
to turn off optimizations), and see if things change.
Well, Clownacy brought it to my attention that I never implemented the ALIGN macros for MSVC.. should look into that.
Fix works great, thanks! 👍