cuckydev / SoniCPort

Sonic the Hedgehog (1991, Sega Genesis / MegaDrive) C Port
128 stars 20 forks source link

Corrupted graphics, misplaced objects #1

Closed kcowolf closed 3 years ago

kcowolf commented 3 years ago

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 5650a16650324a8d5b1392260e49d82019e681bb 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.

Gfx corruption 1 Gfx corruption 2 Gfx corruption 3 Gfx corruption 4

cuckydev commented 3 years ago

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.

cuckydev commented 3 years ago

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.

kcowolf commented 3 years ago

I got mingw-w64 installed and built SoniCPort with it, and it works, so this is definitely specific to MSVC.

deltaphc commented 3 years ago

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.

cuckydev commented 3 years ago

Well, Clownacy brought it to my attention that I never implemented the ALIGN macros for MSVC.. should look into that.

kcowolf commented 3 years ago

Fix works great, thanks! 👍