Fix crash when freeing a vehicle model while its detached parts exist#4947
Open
TheCrazy17 wants to merge 1 commit into
Open
Fix crash when freeing a vehicle model while its detached parts exist#4947TheCrazy17 wants to merge 1 commit into
TheCrazy17 wants to merge 1 commit into
Conversation
Detached car parts spawned by CAutomobile::SpawnFlyingComponent (doors, bonnets etc. flying off an exploding vehicle) are temporary objects that keep the model index of the vehicle they came from, so CObject::Render can repaint them with that vehicle's colours and CObject's destructor can release its model reference. They outlive the vehicle, so deallocating a custom vehicle model (engineFreeModel) while such parts existed made both paths dereference the freed model info (pure virtual call / access violation in CVehicleModelInfo::SetVehicleColour). Clear those references from the object pool when a vehicle model info is deallocated. Also names the two CObjectSAInterface fields involved. Fixes multitheftauto#4911
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a client crash (access violation in
CVehicleModelInfo::SetVehicleColour, offset0x000C84D8) when a custom vehicle model allocated withengineRequestModelis freed after the vehicle exploded.Detached car parts spawned by
CAutomobile::SpawnFlyingComponent(doors, bonnet, etc. flying off an exploding vehicle) are temporary game objects that store the model index of the vehicle they came from (CObject::m_nRefModelIndex+ thebChangesVehColorflag), soCObject::Rendercan repaint them with that vehicle's colours andCObject's destructor can release its model reference. These parts outlive the vehicle element, so deallocating the model while they existed made both paths dereference the freed model info.The fix clears those references from the game's object pool when a vehicle model info is deallocated (
CModelInfoSA::DeallocateModel), the same way the game marks parts without a source vehicle (-1). It also names the twoCObjectSAInterfacefields involved, verified against the documentedCObjectlayout.Motivation
Fixes #4911
Test plan
Using the script from the issue (explode → destroy →
engineFreeModel), which crashed reliably before:destroyElement.blowVehicle, several vehicles sharing the same custom model exploded at once, and re-allocating the same model ID after freeing it.Checklist