IndexOutofRangeException and DivideByZeroExceptionError

After installing the latest update (1.2.1) I am getting spam console errors:

IndexOutOfRangeException: Index was outside the bounds of the array.
DivideByZeroException: Attempted to divide by zero.

Is this because I have set some scrap exchange prices to 0 scrap in the data file? I wanted to disable the selling of cloth to bandit camp, for example, so I set it to 0 scrap for 80 cloth.

Could you provide the full error?

Go0ePa8S2poB3OZ.jpg Wulf

Could you provide the full error?

It just keeps spamming those 2 errors over and over again repeatedly, like this:

12/03 16:56:52 | IndexOutOfRangeException: Index was outside the bounds of the array.

12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:53 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:53 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:56 | IndexOutOfRangeException: Index was outside the bounds of the array.

Right, but your logs should show the full error.

dustyhansen

It just keeps spamming those 2 errors over and over again repeatedly, like this:

12/03 16:56:52 | IndexOutOfRangeException: Index was outside the bounds of the array.

12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:53 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:53 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:53 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:54 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:54 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:55 | DivideByZeroException: Attempted to divide by zero.
12/03 16:56:55 | IndexOutOfRangeException: Index was outside the bounds of the array.
12/03 16:56:56 | IndexOutOfRangeException: Index was outside the bounds of the array.

Did you read the update notes for 1.2.0? There is a warning.

buMBXA6BPKEP0nw.jpg FastBurst

Did you read the update notes for 1.2.0? There is a warning.

Oh I thought that didn't apply to 1.2.1, sorry.

dustyhansen

Oh I thought that didn't apply to 1.2.1, sorry.

Yeah for whatever reason, this plugin does not like to be loaded if the server is already running. It still puzzles me on why it does that.

Increasing the number of sale orders on a vending machine after boot causes IndexOutOfRangeException because the vending machine's refillTimes array is not resized to match the number of sale orders.

Ideally you could resize it, but it's marked as private, and exposing it in Oxide breaks vanilla behavior due to Unity pre-initializing the array which prevents vanilla logic from setting the correct initial capacity.

The recommended solution is cancel the vanilla refill behavior and reimplement it. This is what Custom Vending Setup does, and it does not experience this error.

While you're at it, I also suggest adding sale orders directly, instead of modifying the vendingOrders manifests because the latter cannot really be undone and conflicts with stack plugins like Stack Modifier which try to mitigate vanilla-related issues with vending machines that only manifest when changing stack sizes (i.e., changing stack size of certain items causes certain vending machines to sell more because the vanilla manifests actually declare larger amounts while clamping to max stack size).

buMBXA6BPKEP0nw.jpg FastBurst

Yeah for whatever reason, this plugin does not like to be loaded if the server is already running. It still puzzles me on why it does that.

It is still repeatedly throwing the DivideByZeroException: Attempted to divide by zero. error after the server restarted.

dustyhansen

It is still repeatedly throwing the DivideByZeroException: Attempted to divide by zero. error after the server restarted.

I glanced at the vanilla code for periodically refilling vending machines and confirmed that it should throw a DivideByZeroException when you configure the item to sell for 0 amount, as you stated you did in the original post. If you want to disable setting an item, simply remove that whole {} entry from data file.
NKXTQs24ExGTuL8.jpg WhiteThunder
I glanced at the vanilla code for periodically refilling vending machines and confirmed that it should throw a DivideByZeroException when you configure the item to sell for 0 amount, as you stated you did in the original post. If you want to disable setting an item, simply remove that whole {} entry from data file.

Thanks for the quick reply. Would changing the refill amount or delay to 0 help the same or no? I would prefer not to butcher the data file in case I wish to easily make changes in the future, but if I have to I understand.

It looks like setting the refill delay to a really large number would make the problem go away for most of the time.

If you are concerned about messing up the data file, my suggestion would be to use Custom Vending Setup for editing vending machines since it provides a UI. However, if you are using Compound Options for other features it provides, then I'm not sure to what extent Compound Options is compatible with Custom Vending Setup (i.e., one may override the other in unexpected ways).