瀏覽代碼

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 周之前
父節點
當前提交
a5a572c811
共有 1 個文件被更改,包括 4 次插入0 次删除
  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());