Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite (including camo) swap in the phase report/log #5661

Closed
repligator opened this issue Jul 1, 2024 · 15 comments · Fixed by #5794
Closed

Sprite (including camo) swap in the phase report/log #5661

repligator opened this issue Jul 1, 2024 · 15 comments · Fixed by #5794
Labels
Bug Reports Anything relating in game reporting

Comments

@repligator
Copy link
Collaborator

repligator commented Jul 1, 2024

Environment

Master (latest PR #5784)
Java 17
Linux

Description

I started and finished a game in MM with 4 blue Annihilators vs. 4 red Atlases. The game ran without incident. Then I started another game with 5 Ghost Bear Kodiak II's vs 5 Jade Falcon Turkina's. The mech's and camo are those from the first game. The facing is however correct, and is not carried over from the first game.

sprite_swap_1

Interesting to note: The 5th Kodiak II uses the camo/sprite from the 1st Atlas, and the 4th and 5th Turkina's use the correct camo.
sprite_swap_2

@Sleet01
Copy link
Collaborator

Sleet01 commented Jul 1, 2024

My initial guess is that we're no longer properly clearing the sprite cache at the end of the game, which would be supported by the last two 'mechs using the correct graphics: those unit ids weren't in the first game, so there were no cached graphics for them.

@repligator
Copy link
Collaborator Author

Those are my thoughts as well. I tried smashing out some breakpoints last night, but they all either showed the correct sprite loading, or weren't triggered at all.

@Thom293
Copy link
Contributor

Thom293 commented Jul 1, 2024

A similar thing used to happen with pilot portraits before it was fixed.

@repligator repligator added the Bug label Jul 1, 2024
@repligator
Copy link
Collaborator Author

After smashing some breakpoints in megamek/client/Client.java, it looks like Client never gets the correct sprite and camo. I'm puzzled in regards to how the board is showing the correct one while the phase report doesn't.

@Sleet01
Copy link
Collaborator

Sleet01 commented Jul 4, 2024

After smashing some breakpoints in megamek/client/Client.java, it looks like Client never gets the correct sprite and camo. I'm puzzled in regards to how the board is showing the correct one while the phase report doesn't.

Look at the icon cache, iirc in the game server?

@repligator
Copy link
Collaborator Author

repligator commented Jul 5, 2024

Progress! Sort of...
public static BufferedImage getScaledImage of megamek/common/util/ImageUtil.java will return the correct sprite, with the correct camo, while still in the lobby. As soon as the game starts, it begins to use the wrong sprite and wrong camo.

After smashing some breakpoints in megamek/client/Client.java, it looks like Client never gets the correct sprite and camo. I'm puzzled in regards to how the board is showing the correct one while the phase report doesn't.

Look at the icon cache, iirc in the game server?

Sorry, I'm not sure where/which/what you are referring to.

EDIT: I've found a working sprite under EntitySprite.

@repligator
Copy link
Collaborator Author

repligator commented Jul 8, 2024

This bug is not limited to mechs, or even units of the same type. See screenshot, where a mech has acquired a drop-ship sprite.
Screenshot_20240708_110101

The "Refresh Unit Cache" option under game during games of MegaMek does cause the sprites to correct themselves. It also does nothing if used in the lobby.

@IllianiCBT
Copy link
Collaborator

See also: #5769

@repligator
Copy link
Collaborator Author

Game 1 = Blue Akuma
Game 2= Red Archer
Game 3= Green Atlas II
Red Archer appears as a Blue Akuma in all the round reports for game 2.
Screenshot_20240722_124446
But as soon as reset() happens, it briefly changes back to the Red Archer it should be.
Screenshot_20240722_125245
But the Green Atlass II becomes a Blue Akuma again in game 3.
Screenshot_20240722_125725
And then a Green Atlas II again during reset()
Screenshot_20240722_130117

Here's something else interesting. The log only shows the Blue Akuma "Loading image on the fly"ing, the other two mechs are absent.
I started a 4th game, added two pink mechs, and ID 2 got "Loading image on the fly"ed, in the log, which makes sense, because there was nothing occupying ID 2 in any of the previous games.

megamek.log

@repligator
Copy link
Collaborator Author

Further testing - In a new game I added two Blue Riflemen (ID 1 and 2). I then deleted them from the lobby, and added two Red Piranhas (ID 3 and 4). The Piranhas displayed correctly. After finishing the game with the Red Piranhas, I added two Green Highlanders (ID 1 and 2). The Highlanders became Blue Riflemen in the round reports, and never got "Loading image on the fly"ed. The Blue Riflemen 'stuck' in ID slots 1 and 2, even though they were deleted while in the lobby, and therefor were never displayed in a round report.

megamek.log

@gsparks3
Copy link
Collaborator

Further testing - In a new game I added two Blue Riflemen (ID 1 and 2). I then deleted them from the lobby, and added two Red Piranhas (ID 3 and 4). The Piranhas displayed correctly. After finishing the game with the Red Piranhas, I added two Green Highlanders (ID 1 and 2). The Highlanders became Blue Riflemen in the round reports, and never got "Loading image on the fly"ed. The Blue Riflemen 'stuck' in ID slots 1 and 2, even though they were deleted while in the lobby, and therefor were never displayed in a round report.

This matches some of the similar experiences I've had, where reinforced units would sometimes take on the sprites of units that were added and then removed from the lobby, as opposed to wreck sprites.

@Sleet01
Copy link
Collaborator

Sleet01 commented Jul 22, 2024

It should be noted that the image cache is a separate store from the list of units in the Lobby, and the image cache is not cleared (nor are cached images delete) when a given unit is deleted.

We need to, at the very least, clear the mechImages cache after every game. We should probably also remove the cached images of every unit that is removed from the Lobby list.

@repligator
Copy link
Collaborator Author

Progress! Sort of...
Screenshot_20240723_110359
By adding the two lines (highlighted in red) the issue no longer occurs. Bad news is emptying the cache every single time getFromCache is run kind of invalidates the entire point of the cache existing in the first point. See log.

megamek.log

I've tried adding the lines elsewhere, for example here:
Screenshot_20240723_110800
But the issue persists.

@repligator
Copy link
Collaborator Author

If instead of returning to the lobby, the player exits out further to the start screen (the one with Start New Game, Load Saved Game, Start Scenario, etc.) the issue does not occur.

mechImages.clear() and mechImageList.clear() are currently being run via line number 1137 of megamek/client/ui/swing/ClientGUI.java . Unfortunately they don't quite seem to be working as intended at this location, possibly due to some phase switching shenanigans. From my limited understanding, if the cache is cleared too early (while the mechs still need to be displayed) it will just repopulate itself.

@repligator
Copy link
Collaborator Author

So I inserted getBoardView().getTilesetManager().reset(); under case FILE_REFRESH_CACHE: . This allows reset() to run whenever the Refresh Cache menu option is. I play the first game. Reset() runs naturally when the phase shift occurs. Then I run Refresh Cache from the menu while in an empty lobby. IDEA shows that the mechImageList and mechImages are both empty. I start the second game. The issue still occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reports Anything relating in game reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants