@@ -189,6 +189,11 @@ export default (G: Game) => {
189189
190190 const trg = hexes [ 0 ] . creature || hexes [ 1 ] . creature ;
191191
192+ // Safety check: ensure target exists and is valid
193+ if ( ! trg ) {
194+ return false ;
195+ }
196+
192197 if ( ! trg . stats . moveable ) {
193198 this . message = 'Target is not moveable.' ;
194199 return false ;
@@ -209,10 +214,30 @@ export default (G: Game) => {
209214 const crea = this . creature ;
210215
211216 const hexes = crea . getHexMap ( matrices . inlinefrontnback2hex , this . creature . player . flipped ) ;
217+
218+ // Validate target exists before proceeding
219+ if ( hexes . length < 2 || ( ! hexes [ 0 ] . creature && ! hexes [ 1 ] . creature ) ) {
220+ // No valid target, cancel query
221+ crea . queryMove ( ) ;
222+ return ;
223+ }
212224 const trg = hexes [ 0 ] . creature || hexes [ 1 ] . creature ;
225+
226+ if ( ! trg ) {
227+ // Target validation failed
228+ crea . queryMove ( ) ;
229+ return ;
230+ }
213231
214232 const { size, trgIsInfront, usableHexes } = getEscortUsableHexes ( G , crea , trg ) ;
215233
234+ // Re-validate usable hexes in case remainingMove changed
235+ if ( ! usableHexes . length ) {
236+ this . message = 'Not enough movement points.' ;
237+ crea . queryMove ( ) ;
238+ return ;
239+ }
240+
216241 const select = ( hex ) => {
217242 for ( let i = 0 ; i < trg . hexagons . length ; i ++ ) {
218243 G . grid . cleanHex ( trg . hexagons [ i ] ) ;
@@ -256,6 +281,19 @@ export default (G: Game) => {
256281 G . grid . fadeOutTempCreature ( G . grid . secondary_overlay ) ;
257282 ability . animation ( ...args ) ;
258283 } , // fnOnConfirm
284+ fnOnCancel : function ( ) {
285+ // Cancel query without marking ability as used
286+ G . grid . fadeOutTempCreature ( ) ;
287+ G . grid . fadeOutTempCreature ( G . grid . secondary_overlay ) ;
288+ // Clean up visual states
289+ for ( let i = 0 ; i < trg . hexagons . length ; i ++ ) {
290+ G . grid . cleanHex ( trg . hexagons [ i ] ) ;
291+ }
292+ for ( let i = 0 ; i < crea . hexagons . length ; i ++ ) {
293+ G . grid . cleanHex ( crea . hexagons [ i ] ) ;
294+ }
295+ crea . queryMove ( ) ;
296+ } , // fnOnCancel
259297 fnOnSelect : select , // fnOnSelect,
260298 team : this . _targetTeam ,
261299 id : [ crea . id , trg . id ] ,
0 commit comments