From 32e34cb7bd8d2aef894522872c434b51a36625d4 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Fri, 13 Feb 2026 21:07:52 +0800 Subject: [PATCH] fix: use-after-free crash after piece death --- src/game/GameSession.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game/GameSession.cpp b/src/game/GameSession.cpp index 123f4c4..eb898d0 100644 --- a/src/game/GameSession.cpp +++ b/src/game/GameSession.cpp @@ -117,12 +117,13 @@ bool GameSession::executeAction(int toRow, int toCol) { if (fromPiece->getHP() <= 0) { m_gamePieceEventCallback(GamePieceEvent::REMOVE_PIECE, fromRow, fromCol, -1, -1); m_board->removePieceAt(fromRow, fromCol); + fromPiece = nullptr; } if (toPiece->getHP() <= 0) { m_gamePieceEventCallback(GamePieceEvent::REMOVE_PIECE, toRow, toCol, -1, -1); m_board->removePieceAt(toRow, toCol); - - if (fromPiece->getHP() > 0) { + toPiece = nullptr; + if (fromPiece && fromPiece->getHP() > 0) { m_gamePieceEventCallback(GamePieceEvent::MOVE_PIECE, fromRow, fromCol, toRow, toCol); auto fromInfo = fromPiece->getPieceInfo();