Author Topic: Negative mResidentialCapacity  (Read 304 times)

Offline Archy

  • Newbie
  • *
  • Posts: 5
Negative mResidentialCapacity
« on: June 05, 2020, 09:45:38 AM »
Playing probably my fourth game, thinking I'm getting the hang of it barely. Have about 105 people, but the variable mResidentialCapacity is stuck at -35866109 or some number to that effect.
I debugged a bit but got a bit lost so decided to save the game.
It failed the save saying the savefile doesn't exist (I typed it into the little black box) and then the game just closed....so I have nothing to show sorry.

I then started again and just tried saving a new game:
"Couldn't open 'savegames/MyTest.xml' for writing: not found

I guess it's looking in the wrong location maybe?  All the preloaded savefiles are there in the list though, so I'm not sure why it would try and save in a different folder to the one it's showing.  Maybe it's to do with permissions.

Have read a fair bit on these forums but haven't come across this, so hopefully I didn't miss something.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2264
    • LairWorks Entertainment
Re: Negative mResidentialCapacity
« Reply #1 on: June 05, 2020, 10:26:52 AM »
It does that because it's not looking to write in the program directory (Windows permissions don't allow for that) so they get written to the user directory instead (typically in C:\Users\ somewhere).

The negative capacity is, I think, either an integer overflow or an uninitialized variable. I thought I squashed that... perhaps not. I noticed a similar issue with the resource storage capacity -- I'll have to look into it because those seem to be mostly new? I dunno.

Anyway, I'd recommend deleting any of the save games in data/savegames, should help getting that working properly. If the issue persists let me know -- it's some underlying changes in the NAS2D middleware that aren't playing nice so I'd definitely like to get that taken care of especially if the game just up and quits (probably an unhandled exception being thrown by the filesystem).

Offline Archy

  • Newbie
  • *
  • Posts: 5
Re: Negative mResidentialCapacity
« Reply #2 on: June 06, 2020, 05:15:40 AM »
So without any modifications, the list of savegames available is populated from M:\vs\Repos\OutpostHD\data\savegames
However the saving of files is trying to save them to C:\Users\trent\AppData\Roaming\LairWorks\OutpostHD\savegames
The reason it fails is because there is no such folder.  The savegames folder sits within a "data" folder in the OutpostHD folder

To get it to work, I had to change the savegame location in strings.h
const std::string SAVE_GAME_PATH = "data/savegames/";

Strangely, this changes both where the files save to, and are loaded from.  I mean, it's what you'd expect, but operates differently to how it did without the change.


I then reverted my changes and tried what you said by just deleting savefiles, but that didn't change anything.

With regards to the game just closing after a failed save, the main thread (main.cpp) catches the exception, throws a doNonFatalErroMessage, and then continues on to execute SDL_Quit() which I guess quits everything.

Now I can save, I can try and reproduce the negative capacity stuff.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2264
    • LairWorks Entertainment
Re: Negative mResidentialCapacity
« Reply #3 on: June 06, 2020, 02:00:12 PM »
Sweet. Glad you got some sort of execution path nailed down for it.

It's still an unhandled exception in that it's not caught in the saving code which would prevent it from propagating up to the main function. In int main(...) it has a large try/catch block that encompasses any exceptions that are thrown but not handled higher up -- that's the doNonFatalMessage() call -- it's supposed to provide a message box indicating what's going on as a sort of 'catch all'. It's not the best way to deal with it, definitely one of those work in progress type deals. :D

But it sounds like I've got a general idea of where to focus some efforts next.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4911
Re: Negative mResidentialCapacity
« Reply #4 on: June 09, 2020, 08:00:31 AM »
Sounds like I may have introduced a bug with some of my refactoring. Guess I haven't really tested game saving and loading much.

Thank you for the info.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2264
    • LairWorks Entertainment
Re: Negative mResidentialCapacity
« Reply #5 on: June 12, 2020, 09:39:31 PM »
Eh, it's part of the refactoring process. There's a lot there so it's no surprise that a few things here and there break. :D