Skip to content

Update stb-image port version and improve StbImageLoader#2772

Merged
riccardobl merged 4 commits into
masterfrom
copilot/fix-testq3-assetloadexception
May 12, 2026
Merged

Update stb-image port version and improve StbImageLoader#2772
riccardobl merged 4 commits into
masterfrom
copilot/fix-testq3-assetloadexception

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

TgaDecoder.info() in the stb-image library never set the channels field — it was only populated inside load(). This caused info.getChannels() to return 0 for all TGA images, hitting the default: branch of StbImageLoader's switch and throwing IOException: Unsupported number of channels: 0, crashing any app that loads a TGA texture (e.g. TestQ3). This bug has been fixed upstream in stb-image 2.30.5.

Changes

  • gradle/libs.versions.toml: Updated stb-image dependency from 2.30.4 to 2.30.5, which contains the upstream fix for TgaDecoder.info() not populating channels.

  • selectFormat() helper (new): Extracted the channel-count → Image.Format mapping into a shared private static method, replacing the original inline switch blocks and improving maintainability.

  • convertImageData(): Use imgData.getChannels() (actual output count) instead of imgData.getRequestedChannels() when computing sampleCount for 16-bit/float conversion.

  • StbImageLoaderTest: Regression tests for 24-bit RGB TGA (RGB8) and 8-bit grayscale TGA (Luminance8).

Copilot AI linked an issue May 12, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix AssetLoadException in TestQ3 crash Fix StbImageLoader crash on TGA images (channels=0 from info()) May 12, 2026
Copilot AI requested a review from riccardobl May 12, 2026 11:50
@riccardobl
Copy link
Copy Markdown
Member

@copilot this was actually a bug in the java port of stb-image, it is now fixed in version 2.30.5 , please update the library and remove your workaround. Keep other fixes and tests

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot this was actually a bug in the java port of stb-image, it is now fixed in version 2.30.5 , please update the library and remove your workaround. Keep other fixes and tests

Done in a2755a4. Updated stb-image to 2.30.5 and removed the channels == 0 workaround. Kept the selectFormat() helper refactoring, the convertImageData() fix, and the regression tests.

Copilot AI changed the title Fix StbImageLoader crash on TGA images (channels=0 from info()) Fix StbImageLoader crash on TGA images May 12, 2026
@riccardobl riccardobl marked this pull request as ready for review May 12, 2026 14:46
@riccardobl riccardobl changed the title Fix StbImageLoader crash on TGA images Update stb-image port version and improve StbImageLoader May 12, 2026
@riccardobl riccardobl merged commit fc6b801 into master May 12, 2026
14 checks passed
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.

TestQ3 throws AssetLoadException and crashes

2 participants