Author Topic: Maintenance overflow  (Read 738 times)

0 Members and 1 Guest are viewing this topic.

Offline Antarctica

Maintenance overflow
« on: July 18, 2017, 05:52:47 PM »
My monthly maintenance has just become negative. Somewhere around 86 Million credits a month it silently overflows to -86 million.

86 million is so uncommon a number. Somewhere around 1.25 * 2^26. Now I wonder: what data type are you using there?






Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Maintenance overflow
« Reply #1 on: July 19, 2017, 05:26:27 AM »
Well, first of all, it is not 86 million that is the relevant number in your finances, but 8.6 billions. That is still twice the value where you could expect overflow.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8753
  • Total likes: 305
  • Helpful: 229
  • Languages: De,EN,JP
Re: Maintenance overflow
« Reply #2 on: July 19, 2017, 12:55:24 PM »
Another point I never expected people to ever reach. Same surpricse when in 2004 (and then without any real means to accelerate the game) a Japanese player complained in crashes in 2236, which was the overflow of the game time at that time. (That must have been close to eight months real time!)

But back to your troubles: Is the mainenance really negative, or is this only a conversion problem? (Is there sudden positive influx of money at the end of the month and not reduction as expected?)

Because the maitenacne should be a sint64, in 1/100 of credits, which gives a limit of 92,233,720,368,547,758 or 92 quadrillions. I rather suspect some of the conversion routines into float (which is used to actually display such big numbers) ran into trouble.

To run into the negative maintenance barrier, you need 2^31 objects, with the maximum maintenance cost  of 2^32-1. Since this is unlikely, maybe there is some trouble with the savegame? But I most likely suspecct the display routine.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Maintenance overflow
« Reply #3 on: July 19, 2017, 02:05:27 PM »
I can't see anything wrong with the display routines, but it might be a compiler bug, or even a random runtime bug. An attempt to put the algorithm into a small test program worked fine for 8600000000 centicredits.

Offline Antarctica

Re: Maintenance overflow
« Reply #4 on: July 19, 2017, 03:29:29 PM »
I think you should check the routines adding up maintenance cost, not the display routines, because

- the displayed Maintenance is shown as a positive value,
- the displayed Operational profit at the start of the month is shown as a positive value,
- the displayed Net Wealth makes a jump up (not down) at the start of the month.

Version is rr8249, by the way.



Does it help you if I mention that when it overflowed, I was building tunnels, or is the maintenance calculation function always the same for all objects?

Quote
Same surpricse when in 2004 (and then without any real means to accelerate the game) a Japanese player complained in crashes in 2236
I thought that in 0.80, HaJo already added the possibility to increase simulation time in steps of 0.06? I remember reporting to him a bug that caused lags if you reduced the game speed to 0.13 and increased it to 1 again. Let me see if I find that version on my disk... just to see that we've come such a long way in these nearly 20 years.
« Last Edit: July 19, 2017, 03:40:15 PM by Antarctica »

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Maintenance overflow
« Reply #5 on: July 19, 2017, 03:38:57 PM »
Couldn't it be an overflow in another number that compose the maintenance number? Like some sint16 of a line with many vehicles.

I think we would need the savegame to debug.

Does it help you if I mention that when it overflowed, I was building tunnels, or is the maintenance calculation function always the same for all objects?
It does, but then Ters might be right, a random runtime bug.

Offline Antarctica

Re: Maintenance overflow
« Reply #6 on: July 19, 2017, 03:44:53 PM »
I am not sure I want to provide the savegame. If I decided to, where should I upload it?

Does Google Drive suffice?

Couldn't it be an overflow in another number that compose the maintenance number? Like some sint16 of a line with many vehicles.
Only stations and tracks contribute to the Maintenance total, convois only to Operation Costs. The overflow occurred while the game was paused and I was in underground mode, building new tunnels.
« Last Edit: July 19, 2017, 04:07:26 PM by Antarctica »

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Maintenance overflow
« Reply #7 on: July 19, 2017, 06:24:34 PM »
The strange thing is that the absolute value stays at about eighty millions. Most situations that I can think of that changes the sign would also change the value significantly, unless the value was very near 27, 28, 215, 216, 231, 232, 263 or 264.

Going from about 85899345.92 to about -85899345.92 can happen if four (or eight?) different events each overflow a 32-bit value which are then added into the 64-bit sum one by one.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4224
  • Total likes: 168
  • Helpful: 148
  • Languages: EN, DE, AT
Re: Maintenance overflow
« Reply #8 on: July 19, 2017, 06:35:43 PM »
maintenance is sint32 in finance.h ...

Edit: this savegames takes ages to load, in particularly the stations...
« Last Edit: July 19, 2017, 07:09:26 PM by Dwachs »
Parsley, sage, rosemary, and maggikraut.

Offline TurfIt

Re: Maintenance overflow
« Reply #9 on: July 19, 2017, 06:40:01 PM »
and sint32 per transport type, so if only rail maintenance overflows, road maintenance would still be correct, and the summation shown in the finance screen would be at a non 2^x wrap around point...

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Maintenance overflow
« Reply #10 on: July 19, 2017, 06:44:28 PM »
It can also be scale_with_month_length that is messing things up, perhaps?

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4224
  • Total likes: 168
  • Helpful: 148
  • Languages: EN, DE, AT
Re: Maintenance overflow
« Reply #11 on: July 19, 2017, 07:10:21 PM »
no, this is fully sint64
Parsley, sage, rosemary, and maggikraut.

Offline Antarctica

Re: Maintenance overflow
« Reply #12 on: July 19, 2017, 07:31:14 PM »
Edit: this savegames takes ages to load, in particularly the stations...
For that very reason, I stopped rebooting my computer every night.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Maintenance overflow
« Reply #13 on: July 19, 2017, 07:36:29 PM »
no, this is fully sint64

I was thinking that it masked the actual overflow value. That the raw value in the finance member variable actually is near one of the power-of-twos I listed, but is then turned into this 86 million figure.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4224
  • Total likes: 168
  • Helpful: 148
  • Languages: EN, DE, AT
Re: Maintenance overflow
« Reply #14 on: July 19, 2017, 08:15:42 PM »
Please recheck with r8269 (use nightly). This should fix the overflow issue. It should also speedup the loading process for this savegame.
Parsley, sage, rosemary, and maggikraut.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Maintenance overflow
« Reply #15 on: July 19, 2017, 09:31:39 PM »
Ok, this makes sense, money is saved with cents so with sint32 it can only hold -21 474 836,48, four times this and it's -85 899 345,92 or ~86 millions.

Offline Antarctica

Re: Maintenance overflow
« Reply #16 on: July 20, 2017, 04:09:30 PM »
Yes, rr8269 fixes the overflow issue. Thank you!

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8753
  • Total likes: 305
  • Helpful: 229
  • Languages: De,EN,JP
Re: Maintenance overflow
« Reply #17 on: July 21, 2017, 07:17:26 AM »
Still strange, since this game uses only trains. So it have already should overflow at 2^31/100 ... Maybe some month length arithmetic doing their thing in between.

Anyway, solved.