Skip to content

Image downloads no longer get stuck - #5422

Open
IlluminPhoenix wants to merge 1 commit into
GregTechCEu:1.20.1from
IlluminPhoenix:1.20.1
Open

IlluminPhoenix wants to merge 1 commit into
GregTechCEu:1.20.1from
IlluminPhoenix:1.20.1

Conversation

@IlluminPhoenix

Copy link
Copy Markdown

What

When a client requests an image from the server using the ClientImageCache, if the download fails serverside the server would not notify the client of any fail state and the downloading flag would not be reset and stay true. This prevents any further image requests to the server. This has been fully resolved.
Additionally, if the client Minecraft fails to save the image as a texture (saveTexture) it might fail to reset downloading. This has been partially resolved.

Implementation Details

Added private final boolean downloadSuccess to SPacketImageResponse packet. Additionally, imagePart is only encoded and decoded if the download did succeed:

this.imagePart = downloadSuccess ? buf.readByteArray() : null;
if (downloadSuccess) {
    buffer.writeByteArray(imagePart);
}

This means that imagePart has been moved to the last field and is missing if download has not succeeded.

saveTexture(url, imageBytes);
imageParts.remove(url);
downloading = false;

has turned into

imageParts.remove(url);
downloading = false;
saveTexture(url, imageBytes);

since the saveTexture method fails on certain image formats without any exception or any other error indication and does not return to the normal code path. Specifically this line does not return on some image formats (e.g. JPEG):

Minecraft.getInstance().getTextureManager().register(getUrlTextureId(url), texture);

I do not understand how to prevent this issue as this is not mod code. Currently has just been marked as a todo and has been placed last in order of operations to properly clear the download cache and unset the downloading flag first to prevent soft locking.

AI Usage

  • No AI driven tools were used for this pull request.
  • Yes AI driven tools were used for this pull request.

Agent Used

ChatGPT WebUI

Agent Usage Description

Partially helping me understand the java code and diagnosing, as well as suggesting fix ideas. All code is human written.

Outcome

Image loading now no longer breaks (e.g. when using the image module in the central monitor) when an image download has failed. Now, after a failed download means new image links will be properly processed and downloaded.
Unsure if there is an issue open for this bug.

How Was This Tested

Tested by using central monitor in game to change between valid download links, invalid links and invalid formats to make sure that valid download links will always work, which they do.

Additional Information: -

Potential Compatibility Issues

Changes to format of SPacketImageResponse:
Before:

[int index]
[int totalSize]
[String url]
[byte[] imagePart]

Now:

[int index]
[int totalSize]
[String url]
[boolean downloadSuccess]
[byte[] imagePart]   // only present when downloadSuccess == true

@IlluminPhoenix
IlluminPhoenix requested a review from a team as a code owner September 14, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant