Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #472 setElementHealth in onClientPedDamage can cause crash #3841

Closed

Conversation

FileEX
Copy link
Contributor

@FileEX FileEX commented Nov 3, 2024

Fixes #472

The crash was caused by the fact that for peds other than the local player, the current HP value wasn’t being updated. As a result, the code tried to kill a ped who still had 1 HP, which, due to an invalid pointer, caused a crash. However, this leads to another side effect: due to the ped being recreated, the ped pointer becomes invalid, so the ped never dies with such code.

addEventHandler('onClientPedDamage', root, function()
    setElementHealth(source, 1)
end)

For the local player, it works differently, and the player dies normally. For other players, they’re likely immortal in the same way as non-player peds but i'm not sure.

In any case, recreating the ped in setElementHealth causes a chain of additional bugs and unexpected behaviors. This PR aims to eliminate the crash but doesn’t address the underlying issue with ped recreation

@@ -4394,12 +4394,10 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage,
return false;
}

if (pDamagedPed->IsLocalPlayer())
Copy link
Member

Choose a reason for hiding this comment

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

Wasn't this check added to avoid possible desync issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, since HP will be synchronized when using setElementHealth in onClientPedDamage

Copy link
Member

Choose a reason for hiding this comment

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

HP is synchronized, but a remote player can die locally. It can cause nasty issues potentially

@FileEX FileEX closed this Nov 17, 2024
@FileEX FileEX deleted the bugfix/onClientPedDamage-crash branch November 17, 2024 15:18
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.

setElementHealth in onClientPedDamage can cause crash
3 participants