HarbourMasters / Shipwright

3.3k stars 494 forks source link

Randomizer crashes in opening cutscene if Forest is set to Open #4506

Closed JordanLongstaff closed 3 weeks ago

JordanLongstaff commented 4 weeks ago

I started a Rando game in Hell Mode, and during the cutscene where Navi flies away from the Deku Tree to find Link, I got a crash in soh/src/overlays/actors/ovl_En_Md/z_en_md.c at line 581.

Exception thrown: read access violation.
**pointPos** was 0xFFFFFFFFFFFFFFFF.

Call stack:

>   soh.exe!EnMd_FollowPath(EnMd * this, PlayState * play) Line 581 C
    soh.exe!func_80AABD0C(EnMd * this, PlayState * play) Line 791   C
    soh.exe!EnMd_Update(Actor * thisx, PlayState * play) Line 824   C
    soh.exe!Actor_UpdateAll(PlayState * play, ActorContext * actorCtx) Line 2630    C
    soh.exe!Play_Update(PlayState * play) Line 1138 C
    soh.exe!Play_Main(GameState * thisx) Line 1714  C
    soh.exe!GameState_Update(GameState * gameState) Line 255    C
    soh.exe!Graph_Update(GraphicsContext * gfxCtx, GameState * gameState) Line 302  C
    soh.exe!RunFrame(...) Line 521  C
    soh.exe!Graph_ThreadEntry(void * arg0) Line 553 C
    soh.exe!Main(void * arg) Line 142   C
    soh.exe!SDL_main(int argc, char * * argv) Line 69   C
    soh.exe!main_getcmdline() Line 80   C
    soh.exe!WinMain(HINSTANCE__ * hInst, HINSTANCE__ * hPrev, char * szCmdLine, int sw) Line 110    C
    [External Code] 
JordanLongstaff commented 3 weeks ago

For context, here's the crash, it's in the FollowPath method which is called when Mido walks away from the path leading to the Deku Tree:

u8 EnMd_FollowPath(EnMd* this, PlayState* play) {
    Path* path;
    Vec3s* pointPos;
    f32 pathDiffX;
    f32 pathDiffZ;

    if ((this->actor.params & 0xFF00) == 0xFF00) {
        return 0;
    }

    path = &play->setupPathList[(this->actor.params & 0xFF00) >> 8];
    pointPos = SEGMENTED_TO_VIRTUAL(path->points);
    pointPos += this->waypoint;

    pathDiffX = pointPos->x - this->actor.world.pos.x; // BOOM
    pathDiffZ = pointPos->z - this->actor.world.pos.z;
    Math_SmoothStepToS(&this->actor.world.rot.y, Math_FAtan2F(pathDiffX, pathDiffZ) * (65536.0f / (2 * M_PI)), 4, 4000,
                       1);
// ...
}

It seems to me that setupPathList isn't initialized properly by the time it's called here.

JordanLongstaff commented 3 weeks ago

I think this might be another of the many things that got upended by the VB overhaul of PR #3755.

JordanLongstaff commented 3 weeks ago

I've confirmed it now. If I revert the change that PR made to Mido's actor, the crash is gone.

garrettjoecox commented 3 weeks ago

For reproduction, intro skip needs to be off and you need to set forest to Open

It seems to me that setupPathList isn't initialized properly by the time it's called here.

Not quite that it's not initialized, but it's initialized with different data (likely the pathing that navi takes in this cutscene). A simple check fixed it nice find 👍