sahisahi

Member
Today playing with Xmlspawner i end up with a negative log amount of -180 ish

whenever i tried to lift it up the amount said i was around 65k or so (see pic)

loglog.png
then i tried to change the amount at it didnt let me so seems like a glitch.


So i added this to my log.cs and it got fixed, i wonder if it will mess things up or not, any thoughts?


Code:
        protected override void OnAmountChange( int oldValue )
        {
            int newValue = this.Amount;
            if (this.Amount < 0)
            { 
                this.Delete();
            }
           
        }
 
That is because the amount is over the maximum allowed value for a stack: 65536.
If you create a gold stack of 999999, it will give you 65536 gp, 1gp 65536 gp, 1 gp, etc. until there is nothing left to the original amount.
 
The stack amount in the screenshot is 65,536 - 187 (65,349) because of integer overflow.

The server recognises the amount as being -187 because Item.Amount is a 32-bit signed integer, but the packets sent to the client use an unsigned 16-bit integer, so any negative Item.Amount value will overflow.

If the packet supported a 16-bit signed integer to allow for negative values, it wouldn't make much sense, but if it did, your stack would correctly show -187, but the maximum stack amount would be 32,767 while the minimum being -32,768. This is because the first significant bit is used to store the sign.

An Item.Amount value of greater than 65,536 should overflow in the same way, except it will do it from 0, never being negative.

OK, boring technicalities out of the way, your code should be fine, but perhaps you should investigate why it is going negative in the first place, because all you have is a band-aid and they don't last forever.
 
The stack amount in the screenshot is 65,536 - 187 (65,349) because of integer overflow.

The server recognises the amount as being -187 because Item.Amount is a 32-bit signed integer, but the packets sent to the client use an unsigned 16-bit integer, so any negative Item.Amount value will overflow.

If the packet supported a 16-bit signed integer to allow for negative values, it wouldn't make much sense, but if it did, your stack would correctly show -187, but the maximum stack amount would be 32,767 while the minimum being -32,768. This is because the first significant bit is used to store the sign.

An Item.Amount value of greater than 65,536 should overflow in the same way, except it will do it from 0, never being negative.

OK, boring technicalities out of the way, your code should be fine, but perhaps you should investigate why it is going negative in the first place, because all you have is a band-aid and they don't last forever.

:O

''boring technicialities'' lol

It goes negative because the spawner i have decrease the log stackd amount by -1.

ive been testing it and the logs gets deleted at 0 amount so doesnt seems like it will throw me any error in a near future.

to avoid future issues like players carrying that negative amount around the stack is not movable.

Thank you
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back