GNOME Bugzilla – Bug 701601
Undoing move while showing previous move causes a segmentation fault
Last modified: 2013-06-06 12:46:04 UTC
To reproduce: 1) Start a new game 2) Make a move 3) Press "Show previous move" 4) Select Game->"Undo Move" 5) Observe the application crash The cause seems to be that the ChessScene.move_number does not update as required when undoing a move while showing the previous move. For example, pressing "Undo Move" after making a normal move results in: scene.move_number: -1, game.n_moves: 1 /* Undo black move */ scene.move_number: -1, game.n_moves: 0 /* Undo white move */ However, after showing the previous move, the ChessCene.move_number becomes larger than the ChessGame.n_moves: scene.move_number: 1, game.n_moves: 1 /* Undo black move */ scene.move_number: 1, game.n_moves: 0 /* Attempt to undo white move and fail */ Backtrace: (gdb) bt
+ Trace 232013
(I didn't realize that bugzilla would collapse the stack trace for me) Full backtrace:
+ Trace 232014
Created attachment 246017 [details] [review] Always undo from most the most recent move This makes the Undo action correctly undo the most recent move made, irrespective of what move is currently being displayed.
Review of attachment 246017 [details] [review]: Thank you for this fix, it works great! I'm not sure the loop is needed, though, since all it does is set scene.move_number to -1. Any reason not to just do that instead? (update_board does get called each time scene.move_number is set, but once seems to suffice.)
Created attachment 246055 [details] [review] Always undo from most the most recent move (v2) Hi Michael, thanks - you're right. I was emulating the behavior of history_next_clicked_cb(), but closer inspection of the move_number setter shows that a single assignment as you suggest will do the right thing, with a single update_board() signal emitted if move_number was not already equal -1. Amended patch attached.
Created attachment 246105 [details] [review] Always undo from most the most recent move This makes the in-game undo action always undo the most recent move. This prevents a Segmentation Fault when the user selects "Show previous move" and then attempts to undo move. v2: don't loop on assignment (review from Michael Catanzaro).
I'm not sure what the my above is, other than an accident trying to learn git bz. Anyway I've pushed your patch to master and gnome-3-8, thanks again!
Review of attachment 246055 [details] [review]: Good
I don't think I'll be trying git-bz until bugzilla has an "undo" button! Thanks for the review :-)