Author Topic: [Solved?] Steam Version - System.OutOfMemoryException  (Read 6376 times)

Offline snotvomit

  • Newbie
  • *
  • Posts: 4
[Solved?] Steam Version - System.OutOfMemoryException
« on: November 16, 2009, 06:22:59 pm »
I am playing single player on the STEAM version.  I'm a fair way through a big campaign (first campaign - should have set it smaller really).

I have an intel quad core 3GHz machine running Windows XP home with 2 gig of ram and lots of hard-drive space for the page file.

The error occurs sometimes when saving, and almost always when reloading after quitting from the current game (keeping the game open).

Restarting the game allows the level to be loaded.  My fleets seem really laggy and unresponsive sometimes taking three or four seconds for the beep to confirm orders  - don't know if that's related or whether it's normal for fleets of 2000+ ships.

I saw an earlier thread about this exception, but I haven't found one for the STEAM version.

Any suggestions about how to solve this would be greatly appreciated.


16/11/2009 19:55:09 (2.0)
-----------------------------------Application_ThreadException-----------------------------------System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
   at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
   at System.Text.StringBuilder.Append(String value)
   at AIWar.NetworkServerWrapper.SendGlobalMessage(Boolean SendDirectlyToSelf, NetworkMessageType Type, String Message, Int32 SplitIntoParts) in C:\vcprojs\AIWar\DX\NetworkServerWrapper.cs:line 590
   at AIWar.GameForm.DoFullSync(Boolean IsForSave, Boolean IsForDump, Boolean ShowDialogs, Boolean SendBeginFromLobby, Int32 JustForPlayerNumber) in C:\vcprojs\AIWar\GameFormParts\NetworkHandling.cs:line 1484
   at AIWar.GameForm.DoSaveGame(String Filename, Boolean ShowDialogs) in C:\vcprojs\AIWar\GameFormParts\NetworkHandling.cs:line 1350
   at AIWar.Windows.SaveGame.AfterSaveConfirm(Boolean IsYes) in C:\vcprojs\AIWar\Windows\SaveGame.cs:line 122
   at AIWar.Windows.ModelessConfirm.btnYes_Click(Object sender, EventArgs e) in C:\vcprojs\AIWar\Windows\ModelessConfirm.cs:line 43
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Label.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
« Last Edit: November 17, 2009, 05:33:39 pm by x4000 »

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #1 on: November 16, 2009, 06:44:14 pm »
Can you post the savegame in question so that we can take a look at it?  This is not really something I have seen with the game before, although this prior issue seems similar on the surface, and I assume is what you were referring to:  http://arcengames.com/forums/index.php/topic,186.0.html

That other issue was with string concatenation, which is seemingly similar to your issue here, although in the case of the other it was something that was fixed back in July.  For this one, it is in a different place, and not something I've ever seen before, even on 120-planet maps.  Your save file either must be truly huge, or else there is something strange going on internally.

Can you verify that you are on the .NET Framework 3.5 SP1?  It's possible that you don't have SP1 installed for .NET 3.5, and that this is simply an internal .NET error.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline snotvomit

  • Newbie
  • *
  • Posts: 4
Re: Steam Version - System.OutOfMemoryException
« Reply #2 on: November 16, 2009, 08:18:14 pm »
Definitely .NET version 3.5 SP1 - I checked on "add/remove programs"

I tried attach the save game file, although it is quite big (over 6.5 meg), but I received the following message:


***
Your attachment couldn't be saved. This might happen because it took too long to upload or the file is bigger than the server will allow.

Please consult your server administrator for more information.

 
***

Thanks for the prompt response.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #3 on: November 16, 2009, 08:20:38 pm »
Ah, that save file is the biggest I have ever seen by a large magnitude -- hence the problem in general here, most save files top out at around 2 meg max.  Can you email me that at chrispark7 at gmail dot com?  To be honest, at the moment I'm not sure how you even got a save file quite that large, but I'll take a look at it and see what I can do to make the save performance better.  Thanks!
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline snotvomit

  • Newbie
  • *
  • Posts: 4
Re: Steam Version - System.OutOfMemoryException
« Reply #4 on: November 16, 2009, 08:48:29 pm »
File sent by Email.

This is my first time playing AI War, so maybe I set things way too big.

I was already thinking that, because I'm 50 hours into the game and I'm still only about half way through.  I would like to finish this game if possible, but I've already decided that the playfield will be much smaller (and the AI more difficult) on my next game.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #5 on: November 16, 2009, 08:55:46 pm »
Oh, holy cow -- you're 50 hours through?  You must be one of the completionists, like Kalzarius and others.  Generally you don't want to try to take every AI planet, or even close.  On an 80-planet map, generally the games last 7-16 hours depending on how things go, and you'd take 15-30 of those 80 planets.  On a 120-planet map, I think you'd still take around 30 planets at most if you are playing on an appropriate difficulty level and with a single person.  In general, if you try to take more than that, the AI is likely to kill you if it is at a good level for your skill.  The only two planets you have to kill in order to win the game are the two AI home planets, so if you scout around there is no reason to take planets beyond those that you need for your own resources, those that give you some sort of tactical advantage or new ship (advanced research stations or advanced factories, mainly), and the AI home planets themselves. 

The idea is that if you try to take everything, you are supposed to lose, so the AI must be set to well below your true skill level if you are able to do so well over such an extended period and presumably taking so many planets (I haven't opened the save yet, will most likely in the morning, it's quite late at the moment).

All of the above said, I generally try to make it so that people can play the game the way they want to, so this save file limitation thing is something I'll definitely look at.  And, for that matter, we even have some achievements that are geared towards playing this sort of ultra-completionist style of game, as I'm sure you've noticed, so it's certainly not an "unsupported" mode, it is just an unusual mode.  But this explains why your save file is over 3x larger than any I've ever seen before. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline RCIX

  • Core Member Mark II
  • *****
  • Posts: 2,808
  • Avatar credit goes to Spookypatrol on League forum
Re: Steam Version - System.OutOfMemoryException
« Reply #6 on: November 16, 2009, 10:15:58 pm »
I wouldn't say that 7-16 is the norm, because i'm running F&D on a 70 planet map and i'm 15 hours in  and only halfway or so through...
Avid League player and apparently back from the dead!

If we weren't going for your money, you wouldn't have gotten as much value for it!

Oh, wait... *causation loop detonates*

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #7 on: November 16, 2009, 10:16:59 pm »
Well, okay -- everyone plays it differently, for sure.  From what I have seen in others' savegames, and from what I have played myself and with my testers over the months, that's been what it came out to on average, though.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #8 on: November 17, 2009, 02:42:27 pm »
Wow... just wow... on this savegame.  It's an absolute slideshow even on my quad core (about 1/10 regular speed), but that's because there are 201,106 ships in the game (!?!!).  That's pretty cool that you were able to even get it that high, I've never seen higher than just under 90,000 ships before.  How does this run on your 3GHz dual core?  Probably a lot better than it does on my 2.4Ghz quad, but still I imagine it can't be at full speed... or is it?  I am very curious about that.

Unfortunately, I can't duplicate this issue on my machine -- I've got 4GB of physical memory on a 64bit OS, and that seems to solve the issue.  So I'm going to be shooting a bit blind with a fix for this.  The fact that this works once for you, but not twice or after playing for a while, says to me that this is a memory fragmentation issue with the stringbuilder that is used for saving the games.  I'll try having it force a garbage collection run right before save to try to minimize the likelihood of this, as well as looking into what the capacity setting might be able to do, if anything.  Hopefully one or both of those will avoid the fragmentation issue.

I'll post later today with a new version I, which will have those changes in them.  Thanks for emailing the save!
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #9 on: November 17, 2009, 04:37:06 pm »
Version I will be out later today, but here's more info on what I found out.

Basically, with that absolutely enormous savegame, the game uses around 700 MB of RAM just after loading it.  When saving the game in version H, it would use around 300 MB more right after the save.  Saving again would add around another 100MB to 200MB, and then no matter how many times I saved it would fluctuate between 900MB and 1100 MB total used.

I've revamped how the game handles some of the internals of saving, to make it a hair more efficient in general on RAM use, and so now when I save that huge game, it temporarily spikes around 100 to 200MB on the first go.  Then with each subsequent save, it first drops around 100-300 MB, bringing total memory usage down to around 600-700 MB, and then spikes back up 100 to 200 MB through the save itself.  The save file itself is compressed, by the by, so your 6.5 MB compressed save file clocks in at 26.1 MB when it is uncompressed.  Based on how "string interning" works in .NET, I think this is about as efficient as I can make it on the save for such a huge amount of data, and so hopefully Version I will basically get it back to where you are able to save your game right from the get-go.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Steam Version - System.OutOfMemoryException
« Reply #10 on: November 17, 2009, 05:27:40 pm »
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline snotvomit

  • Newbie
  • *
  • Posts: 4
Re: [Solved?] Steam Version - System.OutOfMemoryException
« Reply #11 on: November 17, 2009, 06:51:55 pm »

I have never before experienced such a thorough and rapid technical support response for a game.  Many thanks  :)

My machine is a quad core 3GHz, but it's actually overclocked to 3.5 GHz and it's very stable.

The game runs fine.  There's a couple of seconds command lag when I'm fighting maybe 4000 AIs with maybe 3000 of my own ships, but still very playable.

Nice to know that I have pushed the game to it's limits.  That's what comes of being a newbie, I suppose :P

I knew that the numbers of ships must be astronomical and I am very impressed that the game can maintain so many units.  I won't be playing single-player with this number of planets once I have finished this campaign, but I am determined to finish this campaign if possible - with this many hours invested, I really feel that I must crush the AI and nothing short of total colonisation will satisfy me.

I now understand that I am far outside the parameters for a "normal" game, so I'll report how things went when I either complete the campaign or the game becomes unplayable.

I can see that there may be no solution to memory/speed issues when things get this big, but at least I'll be able to report the point at which it fails and I'll send the save-game.  If people on the forums would like to examine the save game, I can split the file and upload it as fragments.

Thanks for the link to the latest version.  Am I safe to overwrite the STEAM version of the game?  or should I wait for a STEAM update?




Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: [Solved?] Steam Version - System.OutOfMemoryException
« Reply #12 on: November 17, 2009, 07:13:08 pm »
Wow, that's great to hear about how well it is running for you at that crazy number of units.  That's more than 4x the units it would normally have, so that's way cool that it is working for you.  Always nice to see someone blazing new ground, and pretty amazing to have that many ships in a single game -- that's a new high watermark by far.  My pleasure on the tech support!

For the prerelease, you are absolutely safe to use that with the Steam version if you want.  Bear in mind that it will put you into trial mode for the expansion, but you can easily turn that off and continue playing just the base game, with those updates.  Instructions are in the prerelease thread.  The next official update on Steam won't be for several weeks, so I'd suggest using the prerelease if you want to continue to play this campaign in the shorter term -- and, that will give us an answer to if this solved the issue or not more quickly, as well, which is part of the point or prereleases for the community.

I think you should definitely be able to finish this campaign if it has been doing that well for you in general, hopefully the memory tricks I've put in will make it so that it behaves for you on saving.  Fingers crossed!
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline RCIX

  • Core Member Mark II
  • *****
  • Posts: 2,808
  • Avatar credit goes to Spookypatrol on League forum
Re: Steam Version - System.OutOfMemoryException
« Reply #13 on: November 17, 2009, 08:32:20 pm »
there are 201,106 ships in the game (!?!!)

*jaw drops* .... *faints* *thud*

Ok, i'm back. ;)

Wow. That's amazing? How many thousands is the AI progress? ;) :D
I gotta download this save just to see how bad it is on my machine.
Can you possibly put it up here or is it too big?
Avid League player and apparently back from the dead!

If we weren't going for your money, you wouldn't have gotten as much value for it!

Oh, wait... *causation loop detonates*

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: [Solved?] Steam Version - System.OutOfMemoryException
« Reply #14 on: November 17, 2009, 09:43:33 pm »
Oh, the AI Progress is north of 4000, I forgot to mention.  It's an insane save, yeah. :)

Here's a link:  http://arcengames.com/share/hugeSavegame.sav

This is definitely going in my "test cases" list, since it's such an extreme example.  On my Q6600 quad it is completely unplayable, but it's interesting for saving and loading and such, and I can fantasize that someday I'll have the engine performance to a level where it could handle something remotely like this on my hardware. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!