Skip to content

fix(flame_3d): Use float for numLights uniform to fix GLES crash#3810

Merged
luanpotter merged 3 commits intoflame-engine:mainfrom
agnath18K:fix/flame_3d-gles-uint-crash
Feb 24, 2026
Merged

fix(flame_3d): Use float for numLights uniform to fix GLES crash#3810
luanpotter merged 3 commits intoflame-engine:mainfrom
agnath18K:fix/flame_3d-gles-uint-crash

Conversation

@agnath18K
Copy link
Contributor

Description

Fixes #3809

flame_3d crashes on Android GLES because spatial_material.frag declares uint numLights and lighting_info.dart sets it via shader.setUint(). Impeller's GLES backend only supports float uniforms — the uint path hits an unhandled shader type and crashes.

Changed uintfloat in the shader and setUintsetFloat in Dart. The value is a light count (0–3) so float works identically. Recompiled the shaderbundle.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

No test added — the crash only reproduces on a real GLES device/emulator, not in unit tests. The existing lighting logic is unchanged; only the uniform type is corrected.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

@wolfenrain
Copy link
Contributor

We should verify if this still works on iOS/macos

I don't mind changing it to an float, but if I recall we had weird float issues on the other platforms 😭

@luanpotter
Copy link
Member

I tried on macos - it works!

@luanpotter
Copy link
Member

@agnath18K thanks for your contribution and interest in flame_3d !

do you have a link or reference or github issue to explain "Impeller's GLES backend only supports float uniforms"? so we can add a small comment just for future reference

then I can do the bundle re-gen and merge!

@agnath18K
Copy link
Contributor Author

@agnath18K thanks for your contribution and interest in flame_3d !

do you have a link or reference or github issue to explain "Impeller's GLES backend only supports float uniforms"? so we can add a small comment just for future reference

then I can do the bundle re-gen and merge!

hey @luanpotter , some references for the GLES float-only uniform limitation:
-> The check is in buffer_bindings_gles.cc — validates "Only float uniforms are supported", only calls glUniform*fv variants (engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc)
-> Best example: flutter/engine#55329 — gaussian blur had to swap int sample_count →
float sample_count and cast back in the shader to work around it
Screenshot 2026-02-24 at 12 31 57 AM
https://docs.flutter.dev/ui/design/graphics/fragment-shaders
Related : flutter/engine#55329

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

With the extra info, lgtm!

@luanpotter luanpotter force-pushed the fix/flame_3d-gles-uint-crash branch from 225f03e to fc4208c Compare February 24, 2026 04:03
@luanpotter
Copy link
Member

Rebased and added a note in a comment

@luanpotter luanpotter merged commit f241ebd into flame-engine:main Feb 24, 2026
9 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.

[flame_3d] Fatal crash on Android GLES: uint uniform in spatial_material.frag

4 participants