Skip to content

Conversation

@kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Oct 18, 2025

Identify the Bug or Feature request

Fixes #5819
Fixes #5817

Description of the Change

Makes Token#getTokenImageAssetId() the only way to do lookups in image tables. Any other place that needs to map a token facing to an image now calls Token#getTokenImageAssetId() followed by ImageManager.getImage(MD5Key, ImageObserver[]).

Token#getTokenImageAssetId() itself has been fixed to return Token#getImageAssetId() when a matching entry has no image. The new implementation of the method guarantees that all null cases now Token#getImageAssetId() as a fallback.

TokenRenderer no longer caches image table results, but now calls Token#getImageAssetId() as needed. The calculation for populating the cache was not accurate compared to real table lookups, and there was no cache invalidation. This also meant it leaked memory, as all cached BufferedImage objects would remain in memory forever.

The NPE reported in #5817 is no longer possible because it originated from the TokenRenderer's image table cache.

Possible Drawbacks

None

Documentation Notes

N/A

Release Notes

  • Fixed image table lookup so the correct image is shown for tokens with image tables.
  • Fixed NullPointerException thrown when a token has the "Has image table?" option selected with no image table name specified.

This change is Reviewable

`ImageUtil#getTokenImage(Token, ImageObserver[])` is redundant and has been removed. Any callers of this method can
instead just call `Token#getTokenImageAssetId()` followed by `ImageManager.getImage(MD5Key, ImageObserver[])`.

The `TokenRenderer` no longer tries to cache token images per facing, and instead uses the above technique to get the
image each time. This cache wasn't really functional since entries could never be ejected or updated. Being static, this
also meant it was a memory leak as all the images ever cached would be kept in `TokenRenderer#imageTableMap`.
All `null` results from the image table lookup are now guaranteed to use the fallback to `Token#getImageAssetId()`.
@github-project-automation github-project-automation bot moved this from Awaiting-Review to To-Be-Merged in MapTool 1.18 Oct 19, 2025
@cwisniew cwisniew merged commit 0c70eb5 into RPTools:release-1.18 Oct 19, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from To-Be-Merged to Merged in MapTool 1.18 Oct 19, 2025
@kwvanderlinde kwvanderlinde deleted the bugfix/5819-wrong-image-table-image-shown branch October 20, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

[Bug]: 1.18 - Wrong image shown for tokens with image tables [Bug]: Image Table NullPointerException in 1.18

2 participants