Skip to content

Fix crash from disabling driveby during weapon fire#4968

Merged
Lpsd merged 2 commits into
multitheftauto:masterfrom
TheCrazy17:fix/driveby-crash
Jun 21, 2026
Merged

Fix crash from disabling driveby during weapon fire#4968
Lpsd merged 2 commits into
multitheftauto:masterfrom
TheCrazy17:fix/driveby-crash

Conversation

@TheCrazy17

Copy link
Copy Markdown
Contributor

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 #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

  • 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.

TheCrazy17 and others added 2 commits June 21, 2026 16:25
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 Lpsd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Lpsd Lpsd merged commit bf58b4e into multitheftauto:master Jun 21, 2026
9 checks passed
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>
@TheCrazy17 TheCrazy17 deleted the fix/driveby-crash branch June 23, 2026 01:52
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.

setPedDoingGangDriveby in onClientPlayerWeaponFire crashes game

2 participants