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

Error when using SetVehicleHandling natives with value of 0 #3130

Open
jrgrimshaw opened this issue Feb 5, 2025 · 6 comments · May be fixed by #3134
Open

Error when using SetVehicleHandling natives with value of 0 #3130

jrgrimshaw opened this issue Feb 5, 2025 · 6 comments · May be fixed by #3134
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action

Comments

@jrgrimshaw
Copy link

jrgrimshaw commented Feb 5, 2025

What happened?

The recent merge of PR #3101 stemming from the issue #3097 now prevents the use of 0/0.0 as a valid handling value.

From what I can tell from a look into the codebase and some basic knowledge of C++, the game sees 0 the same as nil and it functionally acts the same from my testing too. I can use nil (in Lua) or 0 interchangeably and get the same results. I understand the original issue's point, I suppose for some handling values nil or 0 can break the physics of the vehicle, but ultimately a lot of different values can completely screw up vehicles to the point where they cannot be fixed.

A float value of 0.0 is valid for various different handling values, and is the default value of many, such as fSuspensionRaise. An int value of 0 is commonly used for signifying no flags, such as for strAdvancedFlags. These also work fine and don't break the vehicle when run in-game.

TL;DR: Using SetVehicleHandlingFloat with a value (arg index 3) of 0.0, the game now sees as invalid even though it should be valid. Same happens when running SetVehicleHandlingInt with a value of 0, it throws the same error.

Expected result

Using SetVehicleHandlingFloat with a value of 0.0 should run without an error.

Reproduction steps

The following code, attempting to 'reset' fSuspensionRaise back to 0.0:

local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
SetVehicleHandlingFloat(vehicle, "CHandlingData", "fSuspensionRaise", 0.0)

Returns the following error, saying arg 3 is nil:
Image

Here's an example repro for strAdvancedFlags, setting a value of 0 to signify no advanced flags should be placed on the vehicle. The error returned is the essentially the same as the above.

local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
SetVehicleHandlingInt(vehicle, "CCarHandlingData", "strAdvancedFlags", 0)

Importancy

Crash

Area(s)

Natives, FiveM

Specific version(s)

FiveM Client 12746 (Currently canary only)

Additional information

No response

@jrgrimshaw jrgrimshaw added bug triage Needs a preliminary assessment to determine the urgency and required action labels Feb 5, 2025
@github-actions github-actions bot added the crash label Feb 5, 2025
@DaniGP17
Copy link
Contributor

DaniGP17 commented Feb 5, 2025

The PR(#3101) that was merged was to avoid null values but the original issue was not for sending null values, because this context.GetArgument<float>(3) already return 0.0 if a null value is sended.
So the real issue is to use 0.0 in the handlers that @CeebDev provide in the issue: fTractionCurveMin / fTractionCurveMax / fLowSpeedTractionLossMult.
Already tested in my server and sending 0.0 value to those handlings get the same issue.

@DaniGP17
Copy link
Contributor

DaniGP17 commented Feb 5, 2025

if (fTractionCurveMax == 0.0f)
{
*(float*)(handlingChar + 140) = 100000000.f;
}

If the handling of fTractionCurveMax is 0.0 it assign a high value, so I'm sure that this is the reason to have strange physics.

@jrgrimshaw
Copy link
Author

The PR(#3101) that was merged was to avoid null values but the original issue was not for sending null values, because this context.GetArgument<float>(3) already return 0.0 if a null value is sended.
So the real issue is to use 0.0 in the handlers that @CeebDev provide in the issue: fTractionCurveMin / fTractionCurveMax / fLowSpeedTractionLossMult.
Already tested in my server and sending 0.0 value to those handlings get the same issue.

I thought so as I didn't see any difference when using 0 or null as a value; either way, the commit should be reverted & the native shouldn't be validated against null values.

@jrgrimshaw
Copy link
Author

if (fTractionCurveMax == 0.0f)
{
*(float*)(handlingChar + 140) = 100000000.f;
}

If the handling of fTractionCurveMax is 0.0 it assign a high value, so I'm sure that this is the reason to have strange physics.

Oh great find! I didn't notice that, yeah that is likely the cause of the strange physics.

@DaniGP17
Copy link
Contributor

DaniGP17 commented Feb 5, 2025

the commit should be reverted & the native shouldn't be validated against null values.

I'm not sure whether to open a PR to revert the previous changes or wait for someone from CFX to revert the commit. Still, I think it's easier to accept null values ​​because as we know they are converted to 0. And the function that does force arguments to be sent seems to take 0.0 as null.

@jrgrimshaw
Copy link
Author

the commit should be reverted & the native shouldn't be validated against null values.

I'm not sure whether to open a PR to revert the previous changes or wait for someone from CFX to revert the commit. Still, I think it's easier to accept null values ​​because as we know they are converted to 0. And the function that does force arguments to be sent seems to take 0.0 as null.

Yeah agreed.

When I wake up tomorrow I'll probably just submit a PR to revert the commit with a bit of an explanation.

@jrgrimshaw jrgrimshaw linked a pull request Feb 6, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants