After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741966 - Saving a completed game due to timeup saves the timer as infinity
Saving a completed game due to timeup saves the timer as infinity
Status: RESOLVED FIXED
Product: gnome-chess
Classification: Applications
Component: General
3.15.x
Other All
: High major
: ---
Assigned To: Sahil Sareen
gnome-chess-maint
Depends on: 742020
Blocks:
 
 
Reported: 2014-12-25 16:39 UTC by Sahil Sareen
Modified: 2014-12-30 17:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Timer shows infinity (80.36 KB, image/png)
2014-12-25 16:39 UTC, Sahil Sareen
  Details
Saving a completed game due to timeup saves the timer as infinity (2.70 KB, patch)
2014-12-29 14:14 UTC, Sahil Sareen
needs-work Details | Review
Saving a completed game due to timeup saves the timer as infinity (2.76 KB, patch)
2014-12-30 13:46 UTC, Sahil Sareen
needs-work Details | Review
Saving a completed game due to timeup saves the timer as infinity (2.28 KB, patch)
2014-12-30 16:56 UTC, Sahil Sareen
committed Details | Review

Description Sahil Sareen 2014-12-25 16:39:21 UTC
Created attachment 293339 [details]
Timer shows infinity

Steps to reproduce:
=====================
1. Set a low time limit in preferences.[to reproduce faster] 
2. Start a new game.
3. Play and finish the game by running out of time.
4. Save the game.
5. Load the saved game.
6. Timer shows as infinity.

Always reproducible.
Attaching a screenshot.
Comment 1 Sahil Sareen 2014-12-29 14:14:36 UTC
Created attachment 293435 [details] [review]
Saving a completed game due to timeup saves the timer as infinity

1. I couldn't find a way to display the final game stats in the header-subtitle as we don't save it in the  file. It would be best to simply continue showing the file_name in the header-subtitle.
2. Fixes showing the infinite time issue.
Comment 2 Michael Catanzaro 2014-12-29 16:39:30 UTC
Review of attachment 293435 [details] [review]:

Works well, thanks.

You have some tab characters that are messing up the indentation; please replace each one with eight spaces.

::: lib/chess-game.vala
@@ +31,3 @@
     DEATH,
+    BUG,
+    NOP_GAME_OVER

I would call this UNKNOWN, and I'd like it to be the first rule in the list -- that way, it gets used by default if we ever forget to initialize a ChessRule explicitly (like in the case you had to guard against here, where the rule defaulted to CHECKMATE).

::: src/gnome-chess.vala
@@ +1530,1 @@
     private string make_clock_text (ChessClock? clock, Color color)

I'd rather the ChessClock be set properly before entering this method, so that you don't have to modify make_clock_text() at all. In start_game(), look in the conditional under the comment "We only support simple timeouts." There is a check to make sure no player is out of time before creating the ChessClock -- remove that check so that the ChessClock gets created even if one player is out of time, and then make_clock_text() should work properly.

Now, the only question is: why did that check exist? I think it was just a bug; I can't think of anything that would break if we remove it.

@@ +1530,3 @@
     private string make_clock_text (ChessClock? clock, Color color)
     {
+	if (pgn_game.result != PGNGame.RESULT_IN_PROGRESS && pgn_game.white_time_left != null)

Even though you'll delete this code anyway, I want to note that it's not safe to trust that black_time_left != null just because white_time_left != null -- the PGN file is untrusted input.
Comment 3 Sahil Sareen 2014-12-30 13:46:49 UTC
Created attachment 293477 [details] [review]
Saving a completed game due to timeup saves the timer as infinity

Thanks for the suggestions Michael!
---
Tested with "no time limit" and with time limits.
Comment 4 Michael Catanzaro 2014-12-30 15:04:40 UTC
Review of attachment 293477 [details] [review]:

::: src/gnome-chess.vala
@@ -466,3 @@
         if (pgn_game.time_control != null && int.parse (pgn_game.time_control) != 0)
         {
-            if (pgn_game.white_time_left != null && pgn_game.black_time_left != null)

But you need this conditional, because again, you can't assume that the PGN file is well-formed. The file might have the time_control flag but not the white_time_left or black_time_left flag, so either of those variables could be null here. Hence this check is needed.

@@ +471,1 @@
+            if (white_seconds >= 0 && black_seconds >= 0)

Did you test this? :)  This condition states that if either player is out of time (which is necessarily the case when this bug occurs), the ChessClock should not be created. This is the one that I think needs to be removed.
Comment 5 Michael Catanzaro 2014-12-30 16:53:20 UTC
(In reply to comment #4)
> @@ +471,1 @@
> +            if (white_seconds >= 0 && black_seconds >= 0)
> 
> Did you test this? :)  This condition states that if either player is out of
> time (which is necessarily the case when this bug occurs), the ChessClock
> should not be created. This is the one that I think needs to be removed.

You pointed out on IRC that you changed the signs from > to >=, so this is actually OK (and better than removing the check, since this way we don't accidentally show negative times remaining).
Comment 6 Sahil Sareen 2014-12-30 16:56:53 UTC
Created attachment 293484 [details] [review]
Saving a completed game due to timeup saves the timer as infinity

Adding back the pgn_game.white_time_left != null && pgn_game.black_time_left != null to handle broken pgn's.
Comment 7 Michael Catanzaro 2014-12-30 17:14:34 UTC
Attachment 293484 [details] pushed as 3c99d3d - Saving a completed game due to timeup saves the timer as infinity