Skip to content

Fix use-after-free when Metal Sonic charges energy balls

Hanicef requested to merge Hanicef/SRB2:metal-sonic-use-after-free into next

During the battle with Metal Sonic, there's a chance that the game crashes when Metal Sonic charges his energy balls. This happens during the charging process, when the energy balls are absorbed into him and is about to fire. In that case, the energy balls are deallocated once they get close enough to Metal Sonic, but due to a missing check, the game still proceeds to run the energy ball logic even after they're are removed from memory, thus crashing the game.

I have also noticed that this always happens in debug mode, so you can easily verify this by just building the game with DEBUGMODE=1. Without this patch, the Metal Sonic fight always crashes when he charges, but behaves as intended with this patch.

Merge request reports

Loading