|
From: <gi...@cr...> - 2026-01-26 03:55:16
|
via 5877fddc77ad08ee2ccc13ec90c5a48b6f141fb4 (commit)
from e1d2b83f61f62d7936308bf84c7dc3a1702f0389 (commit)
-----------------------------------------------------------------------
commit 5877fddc77ad08ee2ccc13ec90c5a48b6f141fb4
Author: gammafunk <gam...@gm...>
Date: Sun Jan 25 21:17:32 2026 -0600
Reset lua state properly for objstat/mapstat
Similar to d744bac7, we now reset lua states and subsequently reload the
necessary data after each iteration. This fixes a problem where large
objstat jobs (e.g. 1000 iterations of generating all of the Dungeon
branch) eventually error repeatedly in zonify layout code. The precise
reason for this hasn't been fully debugged, but it seems to be related
to available lua memory. For now, it's wise to follow the same close ->
reinitialize procedure as we do for the main game loop in each
objstat/mapstat iteration.
Testing has shown that this reset doesn't significantly impact objstat
performance. In the future, when I rework game loop lua reinitializaiton
to more carefully reset and load only the necessary data, we can revisit
needed to close and reopen the lua state for all game modes.
-----------------------------------------------------------------------
Summary of changes:
crawl-ref/source/dbg-maps.cc | 21 ++++++++++++++++++++-
crawl-ref/source/dbg-objstat.cc | 4 ----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/crawl-ref/source/dbg-maps.cc b/crawl-ref/source/dbg-maps.cc
index 5f361c95d0..5b694f7716 100644
--- a/crawl-ref/source/dbg-maps.cc
+++ b/crawl-ref/source/dbg-maps.cc
@@ -253,8 +253,25 @@ bool mapstat_build_levels()
printf("%d..", i + 1);
fflush(stdout);
- dgn_reset_player_data();
+ // At the end of each iteration, the lua state is closed, so we
+ // re-initialize what we need. Skip this for the first iteration,
+ // since it was already done during startup initialization.
+ if (i > 0)
+ {
+ dgn_reset_player_data();
+ init_dungeon_lua();
+ read_maps();
+ run_map_global_preludes();
+ }
+
+ // This is done in a post-init startup phase that was skipped for
+ // mapstat/objstat, so do it here.
+ run_map_local_preludes();
+
+ // Load either the seed in Options or a random seed.
rng::reset();
+ you.game_seed = crawl_state.seed;
+
initial_dungeon_setup();
if (!_build_dungeon())
@@ -262,6 +279,8 @@ bool mapstat_build_levels()
if (crawl_state.obj_stat_gen)
objstat_iteration_stats();
+
+ dlua.close();
}
printf("Finished.\n");
fflush(stdout);
diff --git a/crawl-ref/source/dbg-objstat.cc b/crawl-ref/source/dbg-objstat.cc
index d5464a3e9c..2c1cdf6205 100644
--- a/crawl-ref/source/dbg-objstat.cc
+++ b/crawl-ref/source/dbg-objstat.cc
@@ -1400,10 +1400,6 @@ void objstat_generate_stats()
initialise_item_descriptions();
initialise_branch_depths();
- // We have to run map preludes ourselves.
- run_map_global_preludes();
- run_map_local_preludes();
-
// Populate a vector of the levels ids for levels we're tabulating.
for (branch_iterator it; it; ++it)
{
--
Dungeon Crawl Stone Soup
|