Browse Source

Fix crash when recruiting heroes from tavern

Generate unique instance name for heroes before adding them to the map
during recruitment. This prevents the "Object instance name missing"
error that occurred when clicking the buy button in taverns.

The issue was in visitHeroRecruited() where the hero object was being
added to the map without first setting its instanceName property, which
is required by CMap::addNewObject().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Andrew Hammond 3 weeks ago
parent
commit
a5a572c811
1 changed files with 4 additions and 0 deletions
  1. 4 0
      lib/gameState/GameStatePackVisitor.cpp

+ 4 - 0
lib/gameState/GameStatePackVisitor.cpp

@@ -612,6 +612,10 @@ void GameStatePackVisitor::visitHeroRecruited(HeroRecruited & pack)
 	h->pos = pack.tile;
 	h->updateAppearance();
 
+	// Generate unique instance name before adding to map
+	if (h->instanceName.empty())
+		gs.getMap().generateUniqueInstanceName(h.get());
+
 	gs.getMap().addNewObject(h);
 	assert(h->id.hasValue());