Skip to content

Remove FML_DCHECK around CanReactOnCurrentThread() in `ReactorGLES::CreateUntrackedHandle()#182329

Closed
b-luk wants to merge 2 commits into
flutter:masterfrom
b-luk:createuntrackedhandle
Closed

Remove FML_DCHECK around CanReactOnCurrentThread() in `ReactorGLES::CreateUntrackedHandle()#182329
b-luk wants to merge 2 commits into
flutter:masterfrom
b-luk:createuntrackedhandle

Conversation

@b-luk

@b-luk b-luk commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

ReactorGLES::CreateUntrackedHandle() requires the current thread to have the current opengles context. In environments that use SwitchableGLContext, calling CanReactOnCurrentThread() has the side effect of setting the current opengles context. So it must be called. Having it inside FML_DCHECK made the call only happen in unopt builds, resulting in #182105.

Makes progress on #182105. The GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT issues no longer happen. Newly passing tests:

decode_image_from_pixels_sync_test.dart
encoding_test.dart
image_dispose_test.dart
image_resize_test.dart

codec_test.dart no longer has the GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT error, but still fails. It passes on mac, but on linux it fails with:

[ERROR:flutter/impeller/renderer/backend/gles/blit_command_gles.cc(343)] Break on 'ImpellerValidationBreak' to inspect point of failure: Only textures with pixel format RGBA are supported yet.
[FATAL:flutter/impeller/renderer/backend/gles/blit_pass_gles.cc(88)] Check failed: result. Must be able to encode GL commands without error.

I have a pending fix for this which I will send out afterwards.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Feb 12, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses a bug in ReactorGLES::CreateUntrackedHandle where a function call with side effects, CanReactOnCurrentThread(), was wrapped in an FML_DCHECK. This meant the call was only made in debug builds, causing issues in release builds. The fix moves the function call out of the FML_DCHECK to ensure it is always executed, while still asserting its return value in debug builds. Additionally, several previously skipped tests for OpenGL are re-enabled in run_tests.py, presumably because this fix allows them to pass now. My review includes a suggestion to add a comment explaining the unconditional call and to use const for the local variable, enhancing code clarity and maintainability.

Comment on lines +204 to +205
bool can_react = CanReactOnCurrentThread();
FML_DCHECK(can_react);

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.

medium

This is a good fix. For improved clarity and to prevent future regressions, consider adding a comment explaining why this call is necessary outside of the FML_DCHECK. Also, can_react can be const.

  // This call has side effects (e.g. setting the current GL context) and must
  // be made unconditionally.
  const bool can_react = CanReactOnCurrentThread();
  FML_DCHECK(can_react);

@b-luk b-luk force-pushed the createuntrackedhandle branch from e8bc29b to a698473 Compare February 13, 2026 20:30
@b-luk b-luk force-pushed the createuntrackedhandle branch from a698473 to cc5db37 Compare February 13, 2026 22:44
@b-luk b-luk requested a review from gaaclarke February 13, 2026 22:53
Comment on lines +204 to +205
[[maybe_unused]] bool can_react = CanReactOnCurrentThread();
FML_DCHECK(can_react);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Asked question about this in #182397 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not keen to accept this extra overhead. Do you not need this after my PR that eliminates multithreaded tests?

The issue happens even when multithreading is not enabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we just call directly the thing you need from CanReactOnCurrentThread() directly? The setting of the context.

Can we do that setting of the context once when things are initialized instead of each time we make an untracked handle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think setting the context here directly would be right because we'd only want to do this when a SwitchableGLContext is used (currently only in tests like with TesterContextGLES). We don't want to do this for setups that don't use a SwitchableGLContext (all cases in prod right now).

We can't set the the context once when things are initialized because different things are initialized at different times, potentially in different threads. The current case that is making the tests fail is because the context is not current when creating a texture for an image, which can happen in a different thread than the main frame loop code which also needs to set the current context to do stuff.

TesterContextGLES had to implement this SwitchableGLContext logic in order to work properly with multithreading. Since we no longer are running opengles tests with multithreading enabled, we should be able to simplify TesterContextGLES and remove all of its SwitchableGLContext logic. If we do this, these test should work without calling CanReactOnCurrentThread() here, so this PR should no longer be needed. I'm working on this change to TesterContextGLES now. I'm running into a different problem with that change, but once it's ready I'll send it out and it should make this PR obsolete.

@b-luk

b-luk commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Obsoleted by #183250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants