Skip to content

Fix crash when a custom IMG model is restored while still in use - #5363

Open
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/img-restore-streamout
Open

Fix crash when a custom IMG model is restored while still in use#5363
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/img-restore-streamout

Conversation

@Flashmyname

Copy link
Copy Markdown
Contributor

Summary

SetStreamingInfo force-removes the model's RwObject, and the streamer stops tracking entities that still use it. LinkModel streams those entities out first; UnlinkModel and StreamDisable make the same call without it, so engineRestoreDFFImage - or destroying the IMG element - frees the RW object under live entities.

StreamDisable does call RestreamWorld(), but only after every SetStreamingInfo in the loop has already run, and not at all during session shutdown.

The guard moves into a file-local helper used by all three.

Motivation

The vehicle guard came from #4544 and the weapon one from #5146; neither covered the restore paths. CStreaming::RemoveModel at 0x4089A0 has no reference count - for a vehicle it calls CVehicleModelInfo::DeleteRwObject, which destroys the CVehicleStructure and the master clump regardless of who is using them.

Test plan

Custom IMG holding a banshee.dff, engineImageLinkDFF onto model 429, spawn a Banshee and get in, then engineRestoreDFFImage(429).

Before: 0xC0000005 at gta_sa.exe+0x124765, EAX=0 - CEntity::GetColModel returned null and the render path dereferenced it.

https://streamable.com/kc6ud6

After: the call returns true and the game keeps running.

https://streamable.com/fujmyi

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant