altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

Many Vehicle.GetHandling() setters crash game

Open LightSrc opened this issue 2 years ago • 0 comments

Description of the problem

Game crashes if using too many vehicle handling setters. Getters are fine. For me this happen after changing 2-5 handling values.

Reproduction steps

` using System; using System.Numerics; using System.Text.Json; using AltV.Net.Client; using AltV.Net.Client.Elements.Interfaces;

namespace TestClient { public class VehScript { public VehScript() { Alt.OnPlayerEnterVehicle += PlayerEnterVehicle; }

    public static void PlayerEnterVehicle(IVehicle vehicle, byte seat)
    {
        string json = "{\"fMass\":1400.0,\"fInitialDragCoeff\":0.0008,\"fPercentSubmerged\":85.0,\"vecCentreOfMassOffsetX\":0.0,\"vecCentreOfMassOffsetY\":0.0,\"vecCentreOfMassOffsetZ\":0.0,\"vecInertiaMultiplierX\":1.0,\"vecInertiaMultiplierY\":1.4,\"vecInertiaMultiplierZ\":1.6,\"fDriveBiasFront\":0.8,\"nInitialDriveGears\":5,\"fInitialDriveForce\":0.26,\"fDriveInertia\":1.0,\"fClutchChangeRateScaleUpShift\":1.8,\"fClutchChangeRateScaleDownShift\":1.8,\"fBrakeForce\":0.4,\"fBrakeBiasFront\":1.3,\"fHandBrakeForce\":0.7,\"fSteeringLock\":0.61086524,\"fSuspensionForce\":2.8,\"fSuspensionCompDamp\":0.120000005,\"fSuspensionReboundDamp\":0.21,\"fSuspensionUpperLimit\":0.15,\"fSuspensionLowerLimit\":-0.14,\"fSuspensionRaise\":0.0,\"fSuspensionBiasFront\":1.0,\"fAntiRollBarForce\":0.3,\"fAntiRollBarBiasFront\":1.06,\"fRollCentreHeightFront\":0.24,\"fRollCentreHeightRear\":0.25,\"fInitialDriveMaxFlatVel\":40.27778,\"fCollisionDamageMult\":0.7,\"fWeaponDamageMult\":1.0,\"fDeformationDamageMult\":0.7,\"fEngineDamageMult\":1.5,\"fTractionCurveMax\":2.35,\"fTractionCurveMin\":1.95,\"fTractionCurveLateral\":0.3926991,\"fTractionSpringDeltaMax\":0.15,\"fLowSpeedTractionLossMult\":1.4,\"fCamberStiffnesss\":0.0,\"fTractionBiasFront\":0.97,\"fTractionLossMult\":1.0}";
        VehicleHandlingModel? model = JsonSerializer.Deserialize<VehicleHandlingModel>(json);
        if (model == null) return;
        SetVehicleHandling(vehicle, model);
    }

    public static void SetVehicleHandling(IVehicle theVehicle, VehicleHandlingModel handlingModel)
    {
        Vector3 vecCentreOfMassOffset = theVehicle.GetHandling().CentreOfMassOffset;
        Vector3 vecInertiaMultiplier = theVehicle.GetHandling().InertiaMultiplier;
        foreach (var property in typeof(VehicleHandlingModel).GetProperties())
        {
            Alt.Log("property.Name = " + property.Name);
            Alt.Log("property.Value = " + property.GetValue(handlingModel).ToString());

            if (property.Name == "vecCentreOfMassOffsetX")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecCentreOfMassOffset.X = fVal;
                    theVehicle.GetHandling().CentreOfMassOffset = vecCentreOfMassOffset;
                }
            }
            else if (property.Name == "vecCentreOfMassOffsetY")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecCentreOfMassOffset.Y = fVal;
                    theVehicle.GetHandling().CentreOfMassOffset = vecCentreOfMassOffset;
                }
            }
            else if (property.Name == "vecCentreOfMassOffsetZ")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecCentreOfMassOffset.Z = fVal;
                    theVehicle.GetHandling().CentreOfMassOffset = vecCentreOfMassOffset;
                }
            }
            else if (property.Name == "vecInertiaMultiplierX")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecInertiaMultiplier.X = fVal;
                    theVehicle.GetHandling().InertiaMultiplier = vecInertiaMultiplier;
                }
            }
            else if (property.Name == "vecInertiaMultiplierY")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecInertiaMultiplier.Y = fVal;
                    theVehicle.GetHandling().InertiaMultiplier = vecInertiaMultiplier;
                }
            }
            else if (property.Name == "vecInertiaMultiplierZ")
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    vecInertiaMultiplier.Z = fVal;
                    theVehicle.GetHandling().InertiaMultiplier = vecInertiaMultiplier;
                }
            }
            else if (property.Name == "nInitialDriveGears")
            {
                if (uint.TryParse(property.GetValue(handlingModel).ToString(), out uint iVal))
                {
                    Alt.Log("InitialDriveGears: " + iVal);
                    theVehicle.GetHandling().InitialDriveGears = iVal;
                }
            }
            else
            {
                if (float.TryParse(property.GetValue(handlingModel).ToString(), out float fVal))
                {
                    if (property.Name == "fMass")
                    {
                        theVehicle.GetHandling().Mass = fVal;
                    }
                    else if (property.Name == "fInitialDragCoeff")
                    {
                        theVehicle.GetHandling().InitialDragCoeff = fVal;
                    }
                    else if (property.Name == "fPercentSubmerged")
                    {
                        theVehicle.GetHandling().PercentSubmerged = fVal;
                    }

                    else if (property.Name == "fDriveBiasFront")
                    {
                        theVehicle.GetHandling().DriveBiasFront = fVal;
                    }
                    else if (property.Name == "fInitialDriveForce")
                    {
                        Alt.Log("fInitialDriveForce");
                        theVehicle.GetHandling().InitialDriveForce = fVal;
                    }
                    else if (property.Name == "fDriveInertia")
                    {
                        Alt.Log("fDriveInertia");
                        theVehicle.GetHandling().DriveInertia = fVal;
                    }
                    else if (property.Name == "fClutchChangeRateScaleUpShift")
                    {
                        Alt.Log("fClutchChangeRateScaleUpShift");
                        theVehicle.GetHandling().ClutchChangeRateScaleUpShift = fVal;
                    }
                    else if (property.Name == "fClutchChangeRateScaleDownShift")
                    {
                        Alt.Log("fClutchChangeRateScaleDownShift");
                        theVehicle.GetHandling().ClutchChangeRateScaleDownShift = fVal;
                    }
                    else if (property.Name == "fBrakeForce")
                    {
                        Alt.Log("fBrakeForce");
                        theVehicle.GetHandling().BrakeForce = fVal;
                    }
                    else if (property.Name == "fBrakeBiasFront")
                    {
                        theVehicle.GetHandling().BrakeBiasFront = fVal;
                    }
                    else if (property.Name == "fHandBrakeForce")
                    {
                        theVehicle.GetHandling().HandBrakeForce = fVal;
                    }
                    else if (property.Name == "fSteeringLock")
                    {
                        theVehicle.GetHandling().SteeringLock = fVal;
                    }
                    else if (property.Name == "fSuspensionForce")
                    {
                        theVehicle.GetHandling().SuspensionForce = fVal;
                    }
                    else if (property.Name == "fSuspensionCompDamp")
                    {
                        theVehicle.GetHandling().SuspensionCompDamp = fVal;
                    }
                    else if (property.Name == "fSuspensionReboundDamp")
                    {
                        theVehicle.GetHandling().SuspensionReboundDamp = fVal;
                    }
                    else if (property.Name == "fSuspensionUpperLimit")
                    {
                        theVehicle.GetHandling().SuspensionUpperLimit = fVal;
                    }
                    else if (property.Name == "fSuspensionLowerLimit")
                    {
                        theVehicle.GetHandling().SuspensionLowerLimit = fVal;
                    }
                    else if (property.Name == "fSuspensionRaise")
                    {
                        theVehicle.GetHandling().SuspensionRaise = fVal;
                    }
                    else if (property.Name == "fSuspensionBiasFront")
                    {
                        theVehicle.GetHandling().SuspensionBiasFront = fVal;
                    }
                    else if (property.Name == "fAntiRollBarForce")
                    {
                        theVehicle.GetHandling().AntiRollBarForce = fVal;
                    }
                    else if (property.Name == "fAntiRollBarBiasFront")
                    {
                        theVehicle.GetHandling().AntiRollBarBiasFront = fVal;
                    }
                    else if (property.Name == "fRollCentreHeightFront")
                    {
                        theVehicle.GetHandling().RollCentreHeightFront = fVal;
                    }
                    else if (property.Name == "fRollCentreHeightRear")
                    {
                        theVehicle.GetHandling().RollCentreHeightRear = fVal;
                    }
                    else if (property.Name == "fInitialDriveMaxFlatVel")
                    {
                        theVehicle.GetHandling().InitialDriveMaxFlatVel = fVal;
                    }
                    else if (property.Name == "fCollisionDamageMult")
                    {
                        theVehicle.GetHandling().CollisionDamageMult = fVal;
                    }
                    else if (property.Name == "fWeaponDamageMult")
                    {
                        theVehicle.GetHandling().WeaponDamageMult = fVal;
                    }
                    else if (property.Name == "fDeformationDamageMult")
                    {
                        theVehicle.GetHandling().DeformationDamageMult = fVal;
                    }
                    else if (property.Name == "fEngineDamageMult")
                    {
                        theVehicle.GetHandling().EngineDamageMult = fVal;
                    }
                    else if (property.Name == "fTractionCurveMax")
                    {
                        theVehicle.GetHandling().TractionCurveMax = fVal;
                    }
                    else if (property.Name == "fTractionCurveMin")
                    {
                        theVehicle.GetHandling().TractionCurveMin = fVal;
                    }
                    else if (property.Name == "fTractionCurveLateral")
                    {
                        theVehicle.GetHandling().TractionCurveLateral = fVal;
                    }
                    else if (property.Name == "fTractionSpringDeltaMax")
                    {
                        theVehicle.GetHandling().TractionSpringDeltaMax = fVal;
                    }
                    else if (property.Name == "fLowSpeedTractionLossMult")
                    {
                        theVehicle.GetHandling().LowSpeedTractionLossMult = fVal;
                    }
                    else if (property.Name == "fCamberStiffnesss")
                    {
                        theVehicle.GetHandling().CamberStiffness = fVal;
                    }
                    else if (property.Name == "fTractionBiasFront")
                    {
                        theVehicle.GetHandling().TractionBiasFront = fVal;
                    }
                    else if (property.Name == "fTractionLossMult")
                    {
                        theVehicle.GetHandling().TractionLossMult = fVal;
                    }
                }
            }
        }
    }
}

public class VehicleHandlingModel
{
    public float fMass { get; set; }
    public float fInitialDragCoeff { get; set; }
    public float fPercentSubmerged { get; set; }
    public float vecCentreOfMassOffsetX { get; set; }
    public float vecCentreOfMassOffsetY { get; set; }
    public float vecCentreOfMassOffsetZ { get; set; }
    public float vecInertiaMultiplierX { get; set; }
    public float vecInertiaMultiplierY { get; set; }
    public float vecInertiaMultiplierZ { get; set; }
    public float fDriveBiasFront { get; set; }
    public uint nInitialDriveGears { get; set; }
    public float fInitialDriveForce { get; set; }
    public float fDriveInertia { get; set; }
    public float fClutchChangeRateScaleUpShift { get; set; }
    public float fClutchChangeRateScaleDownShift { get; set; }
    public float fBrakeForce { get; set; }
    public float fBrakeBiasFront { get; set; }
    public float fHandBrakeForce { get; set; }
    public float fSteeringLock { get; set; }
    public float fSuspensionForce { get; set; }
    public float fSuspensionCompDamp { get; set; }
    public float fSuspensionReboundDamp { get; set; }
    public float fSuspensionUpperLimit { get; set; }
    public float fSuspensionLowerLimit { get; set; }
    public float fSuspensionRaise { get; set; }
    public float fSuspensionBiasFront { get; set; }
    public float fAntiRollBarForce { get; set; }
    public float fAntiRollBarBiasFront { get; set; }
    public float fRollCentreHeightFront { get; set; }
    public float fRollCentreHeightRear { get; set; }
    public float fInitialDriveMaxFlatVel { get; set; }
    public float fCollisionDamageMult { get; set; }
    public float fWeaponDamageMult { get; set; }
    public float fDeformationDamageMult { get; set; }
    public float fEngineDamageMult { get; set; }
    public float fTractionCurveMax { get; set; }
    public float fTractionCurveMin { get; set; }
    public float fTractionCurveLateral { get; set; }
    public float fTractionSpringDeltaMax { get; set; }
    public float fLowSpeedTractionLossMult { get; set; }
    public float fCamberStiffnesss { get; set; }
    public float fTractionBiasFront { get; set; }
    public float fTractionLossMult { get; set; }
}

}`

Expected behaviour

Game should not crash.

Additional context

Values are default, taken with theVehicle.GetHandling() for sultan, so there can not be something wrong with values or might be? I found in discord that there might be problem with setting many handling values at the same time which causes game crash https://discord.com/channels/371265202378899476/576771706119520287/870921686042697749 From my test I found out that the game crash is not 100% garanteed, but more likely 90%. Sometimes game doesnt crash until you restart game

Operating system

Windows 11

Version

release/10.10

LightSrc avatar Jun 30 '22 14:06 LightSrc