Skip to content

Fix crash when detaching an element from a colshape hit event - #5185

Merged
FileEX merged 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix-attachcrash
Aug 16, 2026
Merged

Fix crash when detaching an element from a colshape hit event#5185
FileEX merged 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix-attachcrash

Conversation

@TheCrazy17

Copy link
Copy Markdown
Contributor

Summary

DoAttaching moves the attached element to follow whatever it is attached to. Moving a colshape fires its hit and leave events right there, so script handlers run while DoAttaching is still in the middle of the update. If one of those handlers detaches the element, m_pAttachedToEntity turns null while the function is still using it; the lighting sync added in #4984 reads that pointer again after the move, so it crashed on the null pointer. The attachment is now checked again after moving, and the update simply stops there if the element got detached.

Motivation

Fixes #5164. Two hours to reproduce the crash and 2 minutes to fix it.

Test plan

Reproduced it with a small clientside resource: create a ped with a colsphere attached to it, add an onClientColShapeHit handler that calls detachElements when the local player enters, then teleport the ped onto the local player. DoAttaching drags the colshape onto the player, the hit event fires and the handler detaches it; without this change the client crashes right after the handler returns, with this change the detach just works and the game carries on. Also checked that attached objects still take the lighting of the entity they are attached to, so the #4984 behaviour stays intact when nothing detaches.

repro.zip

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.

DoAttaching moves the attached element; for a colshape that fires hit and leave events, so a handler can detach the element in the middle of the update. The lighting sync added in multitheftauto#4984 then used the attach target again without rechecking it and crashed on the null pointer.

Fixes multitheftauto#5164
@FileEX FileEX added the bugfix Solution to a bug of any kind label Aug 16, 2026
@FileEX FileEX added this to the 1.7 (Current) milestone Aug 16, 2026
@FileEX
FileEX merged commit 756e992 into multitheftauto:master Aug 16, 2026
10 checks passed
@TheCrazy17
TheCrazy17 deleted the fix-attachcrash branch August 16, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird crash 0x00044B8B in 1.7 when spawning near another player

2 participants