Bug in StackMetrics.merge (disappearing pieces)

I had this problem a long ago, and even reported it here I think, but it was not solved.

What happens is when a Command generated using

map.placeOrMerge(gp, p)

is undone pieces sometimes disappear.

They are not destroyed, rather the map is no longer aware it has to display such piece.

I think I have nailed when it happens, because other combinations work, unfortunately I can’t show you exact piece of code where it happens (it would require a lot of reading of code that I haven’t written myself, so I’m not eager to do it, you may find the problem faster).

The problem happens only when gp is placed in p, where a single GamePiece is present. If there would be a Stack of 2 or more pieces or At-Start Stack of even a single GamePiece (I don’t know how they differ) the piece would not disappear. I guess the undo code somehow is unable to bring back that single piece.

So to sum it up:

GamePiece moved to Stack location → on undo ok
GamePiece moved to At-Start Stack location → on undo ok
GamePiece moved to GamePiece location → on undo the GamePiece that was already there will disappear.

If you wish I can make in-game movie of that situation, if it will be of some help.

Sorry to post again so quickly; but I have encountered something similar…

Situation: An at start stack that never moves and is always present at the start of any game. If you save your progress and then later load it up, the at start stack is no longer there. It makes up a dynamic part of the board displaying weather so is important to the save…

I would imagine (though know I am likely very wrong to assume) it is because it is never selected or moved or interacted with, at least in its current unfinished form, this will change and I will test it once I have the images in to do so. I was really wondering if this is a known aspect to the game log/ save/load features.

If I can post anything that helps, please let me know what.

Ok, I have confirmed the bug in the code, except that the exact source of it is yet unclear to me.

In a situation where first piece has been moved to point x,y by using placeOrMerge it is placed as a single GamePiece and not a stack.

When a second piece is moved to the same point by using placeOrMerge, a new stack is created, and an AddPiece command recorded for the stack followed by a MoveCommand for the second piece.

On undo this chain is reversed to opposite MoveCommand for the second piece and RemovePiece command for the stack. And this RemovePiece command behaves so that it removes the stack from game, but there is no command in the undo sequence that would place the first piece again in the original point, it is removed with the stack and good bye.

Could someone look why does it happen?

edit: it looks like the bug is in

VASSAL.build.module.map.StackMetrics.merge(GamePiece fixed, GamePiece moving)

because it forgets to record as a command the moment where it creates new stack from the original piece (lines 661-655 in current trunk).

People using Mail2Forum, I think you don’t get notifications when I edit the post, so please come and check this topic:

vassalengine.org/forums/view … 3732#13732

I think I have reduced the source of the bug (and for me it’s quite important bug with disappearing pieces) to just 4 lines.

Yeh, I just tried merging the two pieces of my stack together into one, with more layering and it loads OK, so as you say, its to do with the number in the stack…

Thanks, my problem I hope is solved, good luck with the stacks as a whole :slight_smile: