@@ -394,27 +394,24 @@ class UnoTestState extends MusicBeatState {
394394 // Reset waiting flag first
395395 waitingForHandSwap = false ;
396396
397- // Perform the actual hand swap through the rules system
398- if (performHandSwap != null )
397+ // Perform the actual hand swap through the rules system
399398 performHandSwap (selectedPlayer );
400399
401- // Update UI after swap is complete
402- if (selectedPlayer != null ) {
403- updateInstructionText (' ${currentPlayer .name } swapped hands with ${selectedPlayer .name }!' , true );
404- // Force display update to show new hands
405- updateDisplay ();
406- } else {
407- updateInstructionText (" Hand swap cancelled" , true );
400+ // Update UI after swap is complete
401+ if (selectedPlayer != null ) {
402+ updateInstructionText (' ${currentPlayer .name } swapped hands with ${selectedPlayer .name }!' , true );
403+ // Force display update to show new hands
404+ updateDisplay ();
405+ } else {
406+ updateInstructionText (" Hand swap cancelled" , true );
407+ }
408+ } catch (e : Dynamic ) {
409+ trace (" Error in hand swap callback: " + e );
410+ // Ensure flags are reset even if an error occurs
411+ waitingForHandSwap = false ;
412+ UnoRules .resetHandSwapFlag ();
413+ updateInstructionText (" Hand swap failed" , true );
408414 }
409- performHandSwap = null ;
410- unoGame .onSevenRuleHandSwap = null ; // Clear the handler to prevent reuse
411- return ;
412- }
413- }, function (selectedPlayer : UnoPlayer ) {
414- // Reset waiting flag first
415- waitingForHandSwap = false ;
416-
417- updateInstructionText (" Hand swap cancelled" , true );
418415 });
419416
420417 openSubState (handSwapSubstate );
0 commit comments