Fix crash from disabling driveby during weapon fire#4968
Merged
Conversation
setPedDoingGangDriveby(false) called from onClientPlayerWeaponFire aborted the active driveby task while its own native ProcessPed() was still on the call stack, crashing the game. Defer the abort to the next pulse when called from inside that event.
"The final line of a brace-less condition/loop should be separated for readability": https://github.com/multitheftauto/mtasa-docs/blob/main/mtasa-blue/CODING_GUIDELINES.md#general-coding-practices Also added a comment to make it easier to read/identify
Lpsd
added a commit
to Lpsd/mtasa-blue
that referenced
this pull request
Jun 22, 2026
) ### Summary Defers the native `MakeAbortable()` call for the gang driveby task when `setPedDoingGangDriveby(ped, false)` is called from inside an `onClientPlayerWeaponFire`/`onClientPedWeaponFire` handler, instead of running it immediately. ### Motivation Calling `setPedDoingGangDriveby(localPlayer, false)` from `onClientPlayerWeaponFire` crashes the game. The event fires synchronously from inside the native `CTaskSimpleGangDriveBy::ProcessPed()` call (itself on the stack of `CPlayerPed::ProcessControl`). `MakeAbortable()` frees/nulls a member of the task object; when execution returns into the still-running `ProcessPed()` higher up the stack, it dereferences that now-null pointer and the game crashes with an access violation. Closes multitheftauto#1913 (Crash issues from 2020 lol) ### Test plan - Reproduced the crash with the original repro script (toggling `setPedDoingGangDriveby(localPlayer, false)` from `onClientPlayerWeaponFire` while actively firing in driveby). - Applied the fix and confirmed the same script no longer crashes; the driveby task is aborted on the next pulse instead, and the ped correctly stops doing the driveby animation. ### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit. --------- Co-authored-by: lopsi <40902730+Lpsd@users.noreply.github.com>
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
Defers the native
MakeAbortable()call for the gang driveby task whensetPedDoingGangDriveby(ped, false)is called from inside anonClientPlayerWeaponFire/onClientPedWeaponFirehandler, instead of running it immediately.Motivation
Calling
setPedDoingGangDriveby(localPlayer, false)fromonClientPlayerWeaponFirecrashes the game. The event fires synchronously from inside the nativeCTaskSimpleGangDriveBy::ProcessPed()call (itself on the stack ofCPlayerPed::ProcessControl).MakeAbortable()frees/nulls a member of the task object; when execution returns into the still-runningProcessPed()higher up the stack, it dereferences that now-null pointer and the game crashes with an access violation.Closes #1913 (Crash issues from 2020 lol)
Test plan
setPedDoingGangDriveby(localPlayer, false)fromonClientPlayerWeaponFirewhile actively firing in driveby).Checklist