Skip to content

Fix recursive update when opening bridge image previews - #17

Merged
imol-ai merged 1 commit into
masterfrom
fix/image-preview-recursive-update
Sep 6, 2026
Merged

Fix recursive update when opening bridge image previews#17
imol-ai merged 1 commit into
masterfrom
fix/image-preview-recursive-update

Conversation

@downbtn

@downbtn downbtn commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

idk whats going on ngl codex wrote the patch
fixes crash when opening malformed image links
here's Sol's explanation

The crash is in EdenMod’s preview state handling—not image decoding, Java 26, or Polyfrost.

The crash report (https://mclo.gs/vfYTVws) shows:

IllegalStateException: Recursive update
ConcurrentHashMap.put(...)
ImagePreviewManager.downloadImage(ImagePreviewManager.java:252)
ConcurrentHashMap.computeIfAbsent(...)
ImagePreviewManager.renderPreview(ImagePreviewManager.java:151)

Cause:

  1. src/tel/eden/mod/mixin/GuiGraphicsMixin.java:19 extracts everything after [EDEN_IMG] from the displayed hover text.
  2. Another chat layer has appended \nOpens on click. to that text, so the extracted “URL” is malformed.
  3. src/tel/eden/mod/chat/ImagePreviewManager.java:151 calls downloadImage() inside states.computeIfAbsent(...).
  4. Validation rejects the malformed URL, even though its actual host is trusted.
  5. src/tel/eden/mod/chat/ImagePreviewManager.java:252 calls states.put() for the same key while computeIfAbsent() is still computing it.
    ConcurrentHashMap detects this recursive mutation and throws on the render thread.

Recommended fix:

  • Obtain the canonical URL from style.getClickEvent() when it is a ClickEvent.OpenUrl, using openUrl.uri().toString(). The formatter already
    stores the original URI there in src/tel/eden/mod/chat/DiscordChatFormatter.java:275. Don’t parse the user-visible hover text as the URL.

  • Replace the side-effecting computeIfAbsent with putIfAbsent, then start the download only if this call inserted DOWNLOADING.

  • If the recovered URL still fails validation, leave the ordinary tooltip/link behavior intact instead of cancelling it.

Core state change:

PreviewState state = states.get(url);
if (state == null) {
PreviewState initial =
isPreviewable(url) ? PreviewState.DOWNLOADING : PreviewState.ERROR;
PreviewState previous = states.putIfAbsent(url, initial);
state = previous != null ? previous : initial;

  if (previous == null && initial == PreviewState.DOWNLOADING) {
      downloadImage(url);
      state = states.get(url);
  }

}

This fixes both layers: Discord previews continue working despite tooltip augmentation, and malformed or untrusted URLs can never crash through a
recursive map update. No repository files were changed; this was diagnosis and a proposed patch. Analysis completed in about 2 minutes 20
seconds.

@downbtn

downbtn commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@imol-ai @SirKaiMartin

@SirKaiMartin SirKaiMartin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes and explanation looks good

@imol-ai
imol-ai merged commit 102c922 into master Sep 6, 2026
1 check passed
@imol-ai
imol-ai deleted the fix/image-preview-recursive-update branch September 6, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants