Crashing : Why it Happens Explained (NoCCG and CCG)
4 years ago
United States

All versions can crash, and this can technically happen without CCG but its just more likely to happen with CCG as I'll explain.

Basically SonicTeam decided to allocate three buffers of memory for specific things in-game (or at least three we can see the names to). Note I have not yet confirmed if the sizes are fixed at game initialize or if they are resized per level. Some experiences I've had suggest the latter, but again, unconfirmed.

GLOBAL EVENT ETC

The PS2 version of the game is the only version that still has a printf of the buffers. This is how we know their names and sizes (at least at game init, its never called after that unfortunately): Rest Heap -> (has everything before the three are allocated) Global -> 0x250000 Event -> 0xB80000 ETC -> 0x580000

GLOBAL - Textures, Level Geometry, Level Collision, Audio, Models, Enemies and the like.

EVENT - In-game non-'rendered'/fmv cutscenes, event models, event textures, intros (like glyphic canyon, prison island etc), and goal/completion segments.

  • When an object appears for the first time in view of the player's camera it 'allocates' or takes some memory from GLOBAL and assigns it to that object; The model, texture, and animations occupy this space.
  • When an object disappears this space is 'free'd, given back to GLOBAL.
  • We know that GLOBAL/EVENT are next to each other (from various corruption testing)

When you use Chaos Control or even just go fast, you are constantly loading/unloading level geometry, collision data, enemy textures/models/animations, and hitting triggers.

Here is a very common case of CCG crashing: Notice it crashed after the UI had closed. This happened because when the UI animation completes it frees the memory region it was assigned back to whatever buffer it allocated from. I cannot confirm which buffer UI uses, however it is likely GLOBAL.

A few things might have happened here, but my general hypothesis is this:

Prior land geometry/collision or enemy data failed to unload fast enough while using CC. This causes the new geometry/collision/enemy data to continue overwriting up into the region where the UI memory had been allocated. Then when the free occurs the game quickly ran into a bad/null pointer due to the corrupted memory.

But what if you get lucky? Maybe this happens but the overwritten data is inconsequential. In scenarios where a crash is not immediate, you will generally find the game will be unstable from that point on anyway. This is because when a stage clear happens the buffers regain their full sizes, and sometimes the dangling references are left over or double free'd, causing even more issues.

Another common scenario is the white screen on goal ring for Glyphic Canyon. It's possible the overflow occurred in Westopolis, although it is entirely possible it happens in Glyphic Canyon. In either case, the EVENT buffer either had the pointer to the goal ring event it tries to read corrupted or when freeing the enemies/geometry said free overlaps with another free and then the game hangs.

While developing the 2P mod for this game, this was a huge issue for me as I had to come up with solutions around the constant overflowing. This was the moment I was able to confirm the cause of Shadow's crashes (although I did not know it at the time):

Lastly, we know this game is pushing the boundaries of what they had to work with. Mainly because of the textures being much lower resolution than usual and level geo/models being much lower poly than usual. Either way, the game is on the edge of its limits in some scenarios while you are pushing loading/unloading rapidly.

Edited by the author 4 years ago
Alaska, USA

Do you know why it also happens when the Xbox Version is played on X360? It happened to me a lot when I got to Cryptic Castle the 2nd time.

United States

It happens on all the versions, it does not matter which platform. The above applies to pretty much all the scenarios regardless of level.

Edited by the author 4 years ago
United States

I like this research you did into Shadow the Hedgehog. From when I first began playing this game in 2005 it was clear the game wasn't 100% stable. Nice to see more of the game's inner workings being uncovered.

Game stats
Followers
273
Runs
1,109
Players
71
Latest news
New Shadow Speedrunning Discord Server

Hello all.

We recently created a new discord server to discuss all things Shadow the Hedgehog Speedrunning.

You can join using this invite link:

1 year ago
Latest threads
Posted 2 months ago
8 replies
Posted 1 year ago
Posted 1 year ago
3 replies