yairm210 / Unciv

Open-source Android/Desktop remake of Civ V
Mozilla Public License 2.0
8.32k stars 1.56k forks source link

Large maps result in soft-crashes late game #4925

Closed xotikorukx closed 3 years ago

xotikorukx commented 3 years ago

Platform Windows 10 x64 (64/32 bit).

Version Itch.io Desktop App, 3.16.5-googlePlayPushTest

Describe the bug When attempting to create a randomgen map (default settings) with radius of 128, Unciv straight crashes.

When getting to the end of midgame on a map of 99 radius, every turn rendering dies (UI intact and functions-ish, game board does not exist), and the save file must be reloaded - oddly enough, autosave manages to save correctly, as the save is incremented a turn and loads as expected.

To Reproduce Steps to reproduce the behavior: Load the save, click "Next Turn".

Saved game Autosave-Germany-728.zip (3,116KB is beyond Github's 65536 character limit by far)

Expected behavior The game runs as normal.

Screencap https://youtu.be/canBKXcGsk0

SomeTroglodyte commented 3 years ago

That reminds me I forgot to include the timeout code for worker automation in #4868

SomeTroglodyte commented 3 years ago

... And forgot to require a complete mod list including date of download in the issue template. This is Civ5ExpansionMod.

SomeTroglodyte commented 3 years ago

I'd say no bug. This is just a matter of masochism and patience. Turn finishes in ~70 seconds.

SomeTroglodyte commented 3 years ago

And as for large maps -

Console Log ``` MapGenerator run with parameters (431x280 Hexagonal Pangaea, Seed 1629495812053, 0.7/0.59999996/0.1/0.4/0.05/2/6/0.0) MapGenerator.MapLandmassGenerator took 240.59ms Mountain-like generation for Mountain Hill-like generation for Hill MapGenerator.raiseMountainsAndHills took 1759.10ms MapGenerator.applyHumidityAndTemperature took 337.99ms MapGenerator.spawnLakesAndCoasts took 12084.59ms MapGenerator.spawnVegetation took 82.37ms MapGenerator.spawnRareFeatures took 53.12ms MapGenerator.spawnIce took 210.18ms Natural Wonders for this game: [Grand Mesa, Krakatoa, Barringer Crater, Rock of Gibraltar, El Dorado, Old Faithful, Great Barrier Reef, Mount Fuji, Cerro de Potosi, Fountain of Youth] MapGenerator.NaturalWonderGenerator took 886.60ms MapGenerator.RiverGenerator took 261.18ms chooseSpreadOutLocations: distance 6 < initial 8 chooseSpreadOutLocations: distance 6 < initial 8 chooseSpreadOutLocations: distance 6 < initial 8 chooseSpreadOutLocations: distance 6 < initial 7 chooseSpreadOutLocations: distance 6 < initial 8 chooseSpreadOutLocations: distance 6 < initial 8 chooseSpreadOutLocations: distance 2 < initial 4 chooseSpreadOutLocations: distance 2 < initial 4 MapGenerator.spreadResources took 353343.60ms chooseSpreadOutLocations: distance 6 < initial 8 MapGenerator.spreadAncientRuins took 24857.37ms ```

Map generation took about ~8 Minutes as shown, most of that distributing resources, but we already know that's the bottleneck. Setting up the civs and the rest took another ~8 Minutes, that code has no prepared logging, but it seems there could be some optimization potential there. After that display is fairly quick. You'll need 3GB Ram free for it. Refresh rate at 2-3 FPS. All that on a small NUC, <50W, already running at 100% CPU before starting the test, with debug code.

So playing a 200 radius, 12000 tile map is possible, though only for the unusually patient.

SomeTroglodyte commented 3 years ago

Oh and that save - must be cheated. The parameters say default game speed and starting era, and turn count is 728 as the file name says. No FOW, every tile explored, but no civ has more than two handful cities, >66% of the area unsettled, and the player has only met 3 of the other 15 or so civs. I'd say impossible.

xotikorukx commented 3 years ago

I'd say no bug

Did you watch the video? Time between turns isn't the issue, it's just kinda hard to play when my entire game board disappears.

And as for large maps -...

I'll try to generate a larger map, but I am 90% certain it just crashed to desktop when I tried 128.

Oh and that save - must be cheated. The parameters say default game speed and starting era, and turn count is 728 as the file name says. No FOW, every tile explored, but no civ has more than two handful cities, >66% of the area unsettled, and the player has only met 3 of the other 15 or so civs. I'd say impossible.

I used the Civ5 tileset and expansion mods. I also ran through 10 or so turns as per the video before I was sure it was a bug and not a me thing.

I've got a save from turn 321 where there is still FOW, I'll play from there and see when FoW goes away. I didn't ever do exploration once my starter two warriors got picked off, so I'm not sure where it went. I also see what you mean about all the civs being seen but never met, I'll try to play until that point again too, because cheating defeats the entire purpose of a strategy game.

SomeTroglodyte commented 3 years ago

"cheat" - Sorry my bad. FOW - I forgot there's a tech. AI not settling more than nine cities each - Never tried such a map so I just assumed the AI would grow larger if unchecked. They're at 11 to 19 happiness each and most are in deficit, so I suppose there's code to limit expansion.

Video - no, sorry, no spam sites for me.

I suspect this is a Java version and heap size issue. I'm not running using the bundled JVM or start scripts, so the game has no trouble allocating 4G for that save.

SomeTroglodyte commented 3 years ago

Yup, there's a config in a windoze release package containing "vmArgs": [ "-Xmx1G" ] - that 1G can't be enough for that game size if it's pulling 4G on a Linux box. I can't guess what source or version that bundled JRE is, though. You would probably get a better experience patching that config or better yet fetching a java 16 from adoptopenjdk and running the jar under that with -Xmx4G or more. Which under W10 means at least 16G physical.

xotikorukx commented 3 years ago

So far, setting it allowed to 8GB in the config has solved the issue (I run on a 32GB machine).

No more [unciv, not winblows] blue screens or game crashes yet!

SomeTroglodyte commented 3 years ago

I don't think this setting can be increased by default for all, as I believe it will hurt or even prevent start on small boxes... But I might look into some progress indicator should I ever be bored. And more warnings on the map parameter widget.

yairm210 commented 3 years ago

IIRC we explicitly warn in-game to not set the radius too large. This is definitely a non-bug. I do wonder about the vmArgs. I think that 1gb is definitely enough for a normal user, and any number we set it to would be equally arbitrary, so I think remaining with the current is the way to go.