Skip to content

Fix client crash when firing at streamed-out vehicle wheels#5058

Open
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-weapon-target-streamed-out-vehicle-crash
Open

Fix client crash when firing at streamed-out vehicle wheels#5058
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-weapon-target-streamed-out-vehicle-crash

Conversation

@HeresHavi

Copy link
Copy Markdown

Summary

Added native vehicle and wheel index checks when custom weapons target vehicle wheels.
Streamed-out vehicles now use the vehicle element's cached position instead of trying to access missing wheel data.

Motivation

A streamed-out vehicle can still be a valid Lua element, but it no longer has a native GTA vehicle. Firing a custom weapon at one of its wheels tried to read the wheel position from that missing object and caused an access violation.

For example, a remote turret resource might keep targeting a car wheel as it drives away. If the car streams out before the turret fires again, the next shot could crash the player's client.

Crash Stack
Exception: Access violation (0xC0000005)

CClientWeapon::Fire (CClientWeapon.cpp:260)
CStaticFunctionDefinitions::FireWeapon (CStaticFunctionDefinitions.cpp:7718)
CLuaWeaponDefs::FireWeapon (CLuaWeaponDefs.cpp:195)
image
Reproduction
  1. Created a client-side M4, a nearby control vehicle, and a vehicle far outside the streaming range.
  2. Confirmed the weapon and control vehicle were streamed in while the far vehicle was a valid streamed-out element.
  3. Targeted wheel 0 on the nearby vehicle and fired once. The client remained open.
  4. Targeted wheel 0 on the streamed-out vehicle:
setWeaponTarget(weapon, streamedOutVehicle, 0)
fireWeapon(weapon)

Before the fix, fireWeapon immediately crashed the Debug client with the stack shown above.

Test plan

Runtime

  • Before Fix: Firing at wheel 0 on a valid streamed-out vehicle crashed the Debug client in CClientWeapon::Fire.
  • After Fix: The same target and shot returned true, and the client stayed open. Repeated shots and cleanup/recreation also passed.
  • Valid Case: Firing at wheel 0 on a streamed-in vehicle still returned true.

Builds and Tests

  • Debug | Win32: Build passed, 304 client tests passed.
  • Release | Win32: Build passed, 304 client tests passed.
  • Debug | x64: Server build passed.
  • Ran clang-format.

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.

Check that the targeted vehicle still has native game data before reading its wheel position. Fall back to the vehicle element's cached position when it is streamed out or the wheel index is invalid.
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