RenCloud / scs-sdk-plugin

ETS2 (Euro Truck Simulator 2) & ATS (American Truck Simulator) SDK plug-in. Telemetry data is shared via SharedMemory/Memory Mapped Files.
MIT License
185 stars 35 forks source link

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' #117

Closed Cynicalitz closed 10 months ago

Cynicalitz commented 10 months ago

So exactly on start debugging my WPF C# project I have got an error System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'.

I found its related to this function:

    private SCSTelemetry.Trailer GetTrailer()
    {
        SCSTelemetry.Trailer obj = new SCSTelemetry.Trailer
        {
            WheelsConstant = 
            {
                Steerable = GetBoolArray(16),
                Simulated = GetBoolArray(16),
                Powered = GetBoolArray(16),
                Liftable = GetBoolArray(16)
            },
            Wheelvalues = 
            {
                OnGround = GetBoolArray(16)
            },
            Attached = GetBool()
        };
        SetOffset(3);
        obj.Wheelvalues.Substance = GetUintArray(16);
        obj.WheelsConstant.Count = GetUint();
        obj.DamageValues.Cargo = GetFloat();
        obj.DamageValues.Chassis = GetFloat();
        obj.DamageValues.Wheels = GetFloat();
        obj.DamageValues.Body = GetFloat();
        obj.Wheelvalues.SuspDeflection = GetFloatArray(16);
        obj.Wheelvalues.Velocity = GetFloatArray(16);
        obj.Wheelvalues.Steering = GetFloatArray(16);
        obj.Wheelvalues.Rotation = GetFloatArray(16);
        obj.Wheelvalues.Lift = GetFloatArray(16);
        obj.Wheelvalues.LiftOffset = GetFloatArray(16);
        obj.WheelsConstant.Radius = GetFloatArray(16);
        obj.AccelerationValues.LinearVelocity = GetFVector();
        obj.AccelerationValues.AngularVelocity = GetFVector();
        obj.AccelerationValues.LinearAcceleration = GetFVector();
        obj.AccelerationValues.AngularAcceleration = GetFVector();
        obj.Hook = GetFVector();
        obj.WheelsConstant.PositionValues = GetFVectorArray(16);
        SetOffset(4);
        obj.Position = GetDPlacement();
        obj.Id = GetString();
        obj.CargoAccessoryId = GetString();
        obj.BodyType = GetString();
        obj.BrandId = GetString();
        obj.Brand = GetString();
        obj.Name = GetString();
        obj.ChainType = GetString();
        obj.LicensePlate = GetString();
        obj.LicensePlateCountry = GetString();
        obj.LicensePlateCountryId = GetString();
        return obj; // ######### HERE ######### //
    }

image

hope it's not something I did wrong. If so am sorry for putting it as bug.

RenCloud commented 10 months ago

Hi, thanks for reporting this. This is/was indeed a bug (some kind of race condition). #110 already addressed it, however, I still have not merged it and have not made a release for it. The fix for that is in the dev-branch. But I will make a release ready and merge it to master, so I can finally get rid of it.

I will mark this issue as duplicate, close it when I merged the fix and created the release.

RenCloud commented 10 months ago

Should now be fixed in master as well. If not, this issue can reopen or a new can be created. Thanks.