Jump to content

IndexOutOfRangeException: at MLRS.FireNextRocket ()

Closed 1.4.0 1.5.1

iLakSkiL
iLakSkiL

Posted

Originally posted by @aimacak on Dec. 26, 2023 using version 1.4.0.
 

IndexOutOfRangeException: Index was outside the bounds of the array.
IndexOutOfRangeException: Index was outside the bounds of the array.
  at MLRS.FireNextRocket () [0x0005e] in <08999e34374f48d19390fa37537b5752>:0 
  at InvokeHandlerBase`1[T].DoTick () [0x00109] in <2568dd734f9b44aeb1eb636644ede180>:0 
  at InvokeHandlerBase`1[T].LateUpdate () [0x0000c] in <2568dd734f9b44aeb1eb636644ede180>:0 
iLakSkiL

Posted

Changed Status from Pending to Work in Progress

iLakSkiL

Posted

This is the code for the MLRS entity's method of FireNextRocket, which is being reported where the error is happening.
 

public void FireNextRocket()
    {
        float single;
        ServerProjectile _gravity;
        this.RocketAmmoCount = this.GetRocketContainer().inventory.GetAmmoAmount(2048);
        if (this.nextRocketIndex < 0 || this.nextRocketIndex >= this.RocketAmmoCount || base.IsBroken())
        {
            this.EndFiring();
            return;
        }
        StorageContainer rocketContainer = this.GetRocketContainer();
        Vector3 _position = this.firingPoint.get_position() + (this.firingPoint.get_rotation() * this.rocketTubes[this.nextRocketIndex].firingOffset);
        float single1 = 1f;
        if (this.radiusModIndex < (int)this.radiusMods.Length)
        {
            single1 = this.radiusMods[this.radiusModIndex];
        }
        this.radiusModIndex++;
        Vector2 _insideUnitCircle = (Random.get_insideUnitCircle() * (this.targetAreaRadius - this.RocketDamageRadius)) * single1;
        Vector3 trueHitPos = this.TrueHitPos + new Vector3(_insideUnitCircle.x, 0f, _insideUnitCircle.y);
        if (!base.TryFireProjectile(rocketContainer, 2048, _position, Ballistics.GetAimToTarget(this.firingPoint.get_position(), trueHitPos, this.rocketSpeed, this.vRotMax, this.rocketBaseGravity, this.minRange, out single), this.rocketOwnerRef.Get(true) as BasePlayer, 0f, 0f, out _gravity))
        {
            this.EndFiring();
            return;
        }
        _gravity.gravityModifier = single / -Physics.get_gravity().y;
        Interface.CallHook("OnMlrsRocketFired", this, _gravity);
        this.nextRocketIndex--;
    }



I utilize the hook OnMLRSRocketFired in the plugin to change the default amount of rockets to fire. Otherwise, the MLRS will only shoot a maximum of 12 rockets regardless of how many are put in. Code is below for that

private void OnMlrsRocketFired(MLRS ent, ServerProjectile serverProjectile) 
{
    if ((ent.RocketAmmoCount + rocketsFired) > _config.defsettings.rocketAmount)
    {
        ent.RocketAmmoCount = (_config.defsettings.rocketAmount - rocketsFired);
    }
    if (ent.RocketAmmoCount > 12)
    {
        ent.nextRocketIndex = (int)((ent.RocketAmmoCount % 12) + 1);
        rocketsFired++;
        return;
    }
    else
    {
        ent.nextRocketIndex = ent.RocketAmmoCount - 1;
        rocketsFired++;
        return;
    }
}


The only thing I can think of off the top of my head is that I have my math wrong in the else statement and the subtraction of 1 to the RocketAmmoCount  when setting the nextRocketIndex is making it go out of bounds in certain cases, but I haven't run into this error myself while testing the plugin.

Additionally, @aimacakreported an error in which "MLRS froze and tried to shoot (it was FIRING on the monitor), but for some reason it didn’t shoot, and every attempt to fire a rocket displayed a message in the console." That is odd, because assumingly, it should fire rockets, and only hang up on the last one if the nextRocketIndex reaches -1 (rocket ammo being 0 and then subtracting 1). But even then, when the ammo count is 0, the code should terminate before it doing another call of the OnMLRSRocketFired hook.


If you can try to recreate the situation in which you encountered the error, that would be tremendously helpful. The config settings looked good too, so no idea as of now what caused this.

  • Like 1
aimacak

Posted

Unfortunately, I encountered this once, and I also cannot repeat it 😞 but I believe that this is due to the updates that appeared in 1.4.0, because for about a year of continuous operation of the server, I did not encounter this error.

aimacak

Posted

@iLakSkiL
hi, this happens when they try to launch an odd number of missiles in MLRS (35, 37, etc.) MLRS.Entity itself breaks, you have to delete it ent kill to stop the flood (I haven’t tried restarting the server, but I think it doesn’t matter).

iLakSkiL

Posted

@aimacak

Odd...

Help me quick with a couple questions so I can test it and see:

- What are your stack sizes for mlrs missiles on your server?

- What are you setting the number of rockets to be fired? Is that an odd number?

- Are they placing an odd number of rockets into the MLRS that is less than the maximum it will shoot? (i.e. placing 35 in when max to shoot is 48)

 

The odd number shouldn't matter since, if the ammo left is greater than 12, it divides the total by 12 and returns the remainder plus one. (i.e. 35 % 12 = 11, or 37 % 12 = 1) 
So it will always return a number between 1-12, but never 0 or anything higher than 12, so it should never go out of the index range. So I'm kind of at a loss as to why this would happen. I'll try to do more testing with your parameters and see if I can reproduce it on my end.

aimacak

Posted

@iLakSkiL
1) 24
2) 48
3) yes, player had only 35 rocket both issues 😉 and i check it myself after that

aimacak

Posted (edited)

@iLakSkiL
i changed 12 to 2 and all works fine ❤️ 

 

        private void OnMlrsRocketFired(MLRS ent, ServerProjectile serverProjectile) 
        {
            if ((ent.RocketAmmoCount + rocketsFired) > _config.defsettings.rocketAmount)
            {
                ent.RocketAmmoCount = (_config.defsettings.rocketAmount - rocketsFired);
            }
            if (ent.RocketAmmoCount > 2)
            {
                ent.nextRocketIndex = (int)((ent.RocketAmmoCount % 2) + 1);
                rocketsFired++;
                return;
            }
            else
            {
                ent.nextRocketIndex = ent.RocketAmmoCount - 1;
                rocketsFired++;
                return;
            }
        }

 

        private object OnMlrsFire(MLRS ent, BasePlayer owner)
        {
            ent.SetFlag(BaseEntity.Flags.Reserved6, true, false, true);
            ent.radiusModIndex = 0;
            if (ent.RocketAmmoCount > 2)
            {
                ent.nextRocketIndex = (int)((ent.RocketAmmoCount % 2) + 1);
            }
            else ent.nextRocketIndex = ent.RocketAmmoCount - 1;
            ent.rocketOwnerRef.Set(owner);
            ent.InvokeRepeating(new Action(ent.FireNextRocket), 0f, _config.defsettings.launchTime);
            Interface.CallHook("OnMlrsFired", ent, owner);
            return true;
        }

 

Edited by aimacak
iLakSkiL

Posted

I'll give it a test and see what I come up with.

The only downside to doing a remainder of 2 instead of 12 is that, visually, the MLRS will only fire out of a couple tubes, and not cycle through all 12 tubes when firing a barrage. The plugin prior to v1.4 only shot out of one tube, so I was hoping to fix that and make it more visually appearing.

Hopefully I can figure it out so that it works as intended with an odd number of rockets! Thanks for the info, and hopefully I'll have an update soon.

  • Like 1
iLakSkiL

Posted

Changed Fixed In to Next Version

  • Like 1
iLakSkiL

Posted

Changed Status from Work in Progress to Closed

  • Like 1
1.4m

Downloads

Total number of downloads.

6.9k

Customers

Total customers served.

102.3k

Files Sold

Total number of files sold.

2m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.