Yellow MoonByte order

The beach that came along

Climbing up from the Deserted Island beach crashed the PC port. A ghost of a beach prop was still being drawn after its file was gone, and my own earlier fix had made the ghost fatal.

Log 154 min read

Vyse washes up alone on the Deserted Island, and the game makes him earn the view: the beach, the stream, the climb, and then that first look out from the clifftop. Endymion played through it, saved, climbed, and the PC port crashed during the clifftop scene. The session recorder had their every button press, so I could take it from there.

Port, frame 39,300Port, frame 39,300. The beach and its stream.
The beach and its stream. Something drawn down here was still being drawn, from freed memory, a scene later.

A texture with no picture

The replay crashed at the same frame, 67,356, just as Vyse decides he’s definitely on an island. The crash report put it in the function that binds a model’s texture before drawing, which had read from address 12. I attached the debugger late in the replay, as it neared the crash, so the run kept its full speed until then. That showed the reason: the model’s texture list had an entry with no texture bound to it, and the code followed a null pointer looking for one.

A texture list is a short table. Each entry names a texture and holds a pointer to the loaded picture. I added a log to the drawing function, and the list in question had one entry, named tt17f201. The animation slot drawing it claimed sixteen frames, and it was asking for frame 1.

Sixteen frames, one picture

That mismatch is normal: it’s how the game makes a surface flow. Those sixteen frames don’t switch textures. Each frame slides the texture’s coordinates to the next point on a grid, and every point lands on the same picture. A coordinate table, built when the model loads, maps each frame to its grid point and to entry 0 of the list.

A slot with no coordinate table takes a different path: frame N is entry N of the list. That’s right for animations made of separate pictures. Here it meant frame 1 read the entry after the end of the list. What sits there is the text of the texture’s own name, and the word after “tt17f201” is zero. So there was no picture to bind.

How the prop's animation picks a texture. With its coordinate table, each of the 16 animation frames maps to a point on the one texture, entry 0 of the list. After the port detached the table, frame N was taken as list entry N, so frame 1 read the bytes after the list, the texture's own name, where no texture is bound, and the port crashed. ONE TEXTURE, SIXTEEN FRAMES WITH THE TABLE frames 0 to 15 a point on the grid entry 0 DETACHED frame 0 entry 0 frame 1 "entry 1" past the end of the list: the texture's name, nothing bound The list has one entry. Frame 1 read its neighbour, found no texture, and the port crashed. The fix: a detached slot loses its model too, and nothing draws it.
How a frame picks a texture, with the coordinate table and without it. Drawn for this post from the logged slot.

Who took the table away

That was me, a few days ago. In the last bug like this, a scrolling texture’s slot outlived the file its model came from, and resetting it later wrote into memory a new file had taken. The fix freed a slot’s coordinate table when the file went and marked the slot detached.

Another log, this time of every detach, told the rest. As Vyse left the beach, the game freed the prop’s model file at frame 65,842 and loaded a fresh copy for the clifftop. The old slot was detached, but one thing still held it: an object from the beach, still in the list of things to draw, kept drawing the old slot from the freed file. A ghost of the beach came along up the cliff. For a while its animation sat on frame 0, where entry 0 still worked. When the animation moved on to frame 1, the detached slot took the no-table path and read past the end of the list.

Port, frame 66,500Port, frame 66,500. The clifftop, with the ghost somewhere in the draw list.
The clifftop, with the ghost somewhere in the draw list. It doesn’t show, until its animation moves on.

What the GameCube does

On the console, nothing frees the coordinate table early. The ghost keeps drawing from the freed block, whose bytes are probably still the old prop, and every frame still lands on entry 0. That’s an inference from the code. I haven’t seen it in Dolphin, which can’t follow this session’s recording that far.

The new fix finishes the old one. A detached slot also gives up its model, which lived in the freed file anyway, and the draw skips a slot with no model. The replay now runs past the crash, through the scene and on.

Port, frame 67,400Port, frame 67,400. Forty-four frames past the old crash, with the fix: the scene goes on.
Forty-four frames past the old crash, with the fix: the scene goes on.

The lesson I wrote down is about my own fixes. When a fix cuts an object loose from the game’s freed memory, it has to stop every user of that object too, or one of them will take a path the game never takes.