Repository navigation
Conversation
A freshly spawned NPC was spawned again inside NPC_PutInVehicle, so OnPlayerSpawn ran twice and could delete the vehicle mid-call.
|
Tested this independently on Windows, RelWithDebInfo, Win32 + ClangCL (same setup as CI), with the PR merged on top of current All cases run headless (NPCs only, no client) and shut the server down by themselves.
Case 5 checks the slot-reuse edge case of the Also ran clang-format 13 with the repo's One behaviour note, unchanged by this PR: in case 4 the NPC also leaves vehicle A, because putting a seated NPC into another vehicle still goes through LGTM from testing. |
NPC_PutInVehiclespawns the NPC again if it is notPlayerState_OnFoot. Right afterNPC_Spawnthe NPC is stillPlayerState_Spawned, so it gets spawned a second time andOnPlayerSpawnruns inside the native. If the script destroys the vehicle there,putInVehiclekeeps using it.The crash
Access violation in Vehicles.dll, executing an address that is not code. In the minidump the vehicle's vtable pointer is already
IExtensible::vftable(its destructor has run), sovehicle.getModel()at npc.cpp:1556 jumps into data.NPC::respawncan hit the same thing: it keeps the vehicle pointer across its ownPlayerSpawnRPC, which also runsOnPlayerSpawn.Without the destroy it does not crash, but
OnPlayerSpawnstill runs twice and the second spawn resets health, armour and weapon.Repro
Crashes every time on 3d20f3d:
Fix
PlayerState_Spawnedcounts as spawned, so there is no second spawn.falseif it is not.respawndoes the same check.NPC_PutInVehicle(Pawn and CAPI) returns the real result instead of alwaystrue.Tested
Windows, RelWithDebInfo, same tree before and after:
OnPlayerSpawnonce, NPC seatedNPC_Spawn, set weapon and health,NPC_PutInVehicleOnPlayerSpawntwice, weapon and health resetOnPlayerSpawnonce, weapon and health keptNPC_Respawnwhile seated,OnPlayerSpawndestroys the vehicleOnPlayerSpawndestroys the secondfalse, NPC not seated