Page 1 of 1

Second Game Bug

PostPosted: 18 Aug 2012, 01:23
by friarsol
There's been a bug that seemed to slip in just after the last beta was released. I haven't had time to fully debug it since I haven't been home, but I did a little bit this afternoon while on a bus and it looks like the hang up is trying to structure the layout. Now I'm not sure exactly why it needs to do all this in between games, since no UI is visible (yet) and no cards are on the battlefield (yet).

Stack Trace | Open
Arrays.copyOf(T[], int) line: not available
PlayArea$CardStackRow(ArrayList<E>).clone() line: not available
PlayArea.canAdjustWidth(PlayArea$CardStackRow, PlayArea$CardStackRow, PlayArea$CardStackRow, PlayArea$CardStackRow) line: 318
PlayArea.doLayout() line: 219
PlayArea(Container).validateTree() line: not available
JViewport(Container).validateTree() line: not available
JScrollPane(Container).validateTree() line: not available
FPanel(Container).validateTree() line: not available
DragCell(Container).validateTree() line: not available
JPanel(Container).validateTree() line: not available
FPanel(Container).validateTree() line: not available
FPanel(Container).validate() line: not available
SResizingUtil.resizeWindow() line: 96
SLayoutIO.load(File) line: 191
SLayoutIO.loadLayout(File) line: 75
VMatchUI.populate() line: 54
FControl.changeState(int) line: 201
GameNew.newGame(Deck, Deck, CardList, CardList, int, int, String) line: 63


It appears this happens prior to the previous cards are cleared from all zones (I'm not exactly sure why this doesn't happen sooner than it does).

From what I can tell, there's a Binary Search that is attempting to find the "best" value to fit the screen to. For whatever reason a suitable match is never found (I guess due to a 0 screen width and cards existing in a visible zone) When I paused during this infinite loop, the value was less than -150k. I tried to clear the cards in the zones earlier, but that doesn't seem to want to work for starting the first game.

But the culprit seems to be here:

Code: Select all
            // if it did not fit this time, let it fit with a one-pixel less size
            if ( !workedLastTime && step == 0 ) {
                step = 1;
            }
which will infinitely reset the binary loop and completely remove the base condition.

I've added a break if the cardwidth ever becomes 0 or negative, which seems to have resolved the game 2 issues, if someone more familiar with the code has a better fix feel free to go for it.

Re: Second Game Bug

PostPosted: 19 Aug 2012, 09:42
by Max mtg
This one should by no means become less than 50. A check for this condition was somewhere inside doWrap or simliar code. It appears that under some circumstances (wish I knew under which ones), the alignment cannot be done with ever decreasing card size.

The old code was iterating from maxCardWidth to 50 until it found a good width. Each calculation is cpu-intensive. So I apllied a binary search alogrithm here to reduce the number of calls from N to log2(N).
The quoted lines were to give the code a chance to rollback to previous width if the last value didn't fit into the playarea. That increment should have been made only once per cycle.

Re: Second Game Bug

PostPosted: 19 Aug 2012, 15:49
by friarsol
Max mtg wrote:This one should by no means become less than 50. A check for this condition was somewhere inside doWrap or simliar code. It appears that under some circumstances (wish I knew under which ones), the alignment cannot be done with ever decreasing card size.

The old code was iterating from maxCardWidth to 50 until it found a good width. Each calculation is cpu-intensive. So I apllied a binary search alogrithm here to reduce the number of calls from N to log2(N).
The quoted lines were to give the code a chance to rollback to previous width if the last value didn't fit into the playarea. That increment should have been made only once per cycle.
Makes sense. It happens every time for me when starting a second game (on this computer), even just conceding a constructed game. I think what I was noticing was:

Step is 256, width is something just barely higher than that (maybe 350). And we get the following:

350 fails. W=94; S=128. (S should probably be greater than W at this point)
94 fails. W=-34.
....
-X fails. W=-X-1. S=1.
-Y fails. W=-Y-1. S=0, then S=1.

And it's an infinite loop from there.

Re: Second Game Bug

PostPosted: 19 Aug 2012, 20:42
by Jaedayr
I just want to note that this fix also appears to fix the first game problem I have had while questing, i.e. no pets appear and there are no cards in either hand. I have not seen it since I downloaded the latest daily build.

Thank you Sol! =D> =D> =D> =D> =D>