From 2eeb245b98bd702379aa92d888f7b7d21d1193b8 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 26 Mar 2024 17:40:37 +0100 Subject: C++ migration: Fix metatable caching bug introduced when converting the index to std::atomic --- src/tools.cpp | 2 +- src/universe.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tools.cpp b/src/tools.cpp index 89e5499..52c70bc 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -632,7 +632,7 @@ static lua_Integer get_mt_id( Universe* U, lua_State* L, int i) if( id == 0) { - id = U->last_mt_id.fetch_add(1, std::memory_order_relaxed); + id = U->next_mt_id.fetch_add(1, std::memory_order_relaxed); /* Create two-way references: id_uint <-> table */ diff --git a/src/universe.h b/src/universe.h index 3aac20d..bb3ebdd 100644 --- a/src/universe.h +++ b/src/universe.h @@ -154,7 +154,7 @@ struct Universe // require() serialization std::recursive_mutex require_cs; - std::atomic last_mt_id{ 0 }; + std::atomic next_mt_id{ 1 }; #if USE_DEBUG_SPEW() int debugspew_indent_depth{ 0 }; -- cgit v1.2.3-55-g6feb