Skip to content

fix: Find CameraComponent.postProcess in findPostProcessFromContext - #4221

Merged
ufrshubham merged 7 commits into
mainfrom
devkage/fix-camera-post-process-context
Nov 16, 2026
Merged

ufrshubham merged 7 commits into
mainfrom
devkage/fix-camera-post-process-context

Conversation

@ufrshubham

@ufrshubham ufrshubham commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Description

findPostProcessFromContext returned null for every component rendered under CameraComponent.postProcess. Its fallback looked for a CameraRenderContext among the render contexts of the component's ancestors, but render contexts are only passed on through renderChild, and the camera renders its world, viewfinder and viewport by calling their renderTree directly. That lookup could never succeed, so a multi-pass post process set on the camera had no way to tell its components which pass they were being rendered in, like the selection highlight in #4200.

The lookup now goes through CameraComponent.currentCameras instead, from the innermost camera outwards, and returns the first post process of the requested type that is currently rendering, the same way CullWhenOffscreen finds the camera that renders it. A PostProcessComponent ancestor still takes precedence. Components in the viewport or the backdrop still get null, since they aren't rendered through the post process, and so do the components of the same world rendered by another camera without a post process.

camera_context_bug_selection_fixed.mp4

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.

Breaking Change?

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

Related Issues

Closes #4200

`findPostProcessFromContext` returned `null` for every component in the
world and in the viewfinder when the post process was set as
`CameraComponent.postProcess`. Multi-pass effects where components draw
differently in each pass couldn't work with the camera's post process.
For example, a selection highlight that renders a mask of the selected
unit and then the scene outlined every component instead.

The lookup fell back to the camera's render context, but render contexts
are only passed from a component to its children, and the camera renders
the world and the viewfinder directly, so that context never reached
them. Now the fallback checks the post processes of the cameras that are
rendering, through `CameraComponent.currentCameras`, from the innermost
to the outermost. A `PostProcessComponent` ancestor still takes
precedence.

This also adds a repro example, `camera_context_repro.dart`.
@ufrshubham ufrshubham self-assigned this Nov 10, 2026
@ufrshubham
ufrshubham requested review from a team and a balanced review from Copilot November 10, 2026 18:25

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the camera post-process lookup change.

No open issues 🎉

What changed in this PR

Fixes #4200 by allowing components rendered through CameraComponent.postProcess to find the active post process, enabling multi-pass effects to identify their current rendering pass.

Changes:

  • Replaces the camera render-context fallback with an innermost-to-outermost lookup through active cameras, preserving ancestor post-process precedence.
  • Documents lookup behavior and adds regression tests for world, viewfinder, nested-camera, and shared-world rendering.
File Description
packages/​flame/​test/​post_process/​post_process_context_test.dart Adds regression coverage for camera post-process discovery and isolation.
packages/​flame/​lib/​src/​post_process/​post_process_component.dart Updates and documents the active-camera fallback lookup.

Review effort: Balanced

@spydon spydon left a comment

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.

Lgtm!

@ufrshubham
ufrshubham enabled auto-merge (squash) November 16, 2026 19:00
@ufrshubham
ufrshubham merged commit 48979ab into main Nov 16, 2026
9 checks passed
@ufrshubham
ufrshubham deleted the devkage/fix-camera-post-process-context branch November 16, 2026 19:05
LordixDemon added a commit to LordixDemon/flame that referenced this pull request Nov 17, 2026
Brings in the upstream fix for findPostProcessFromContext (flame-engine#4221), the
package skills (flame-engine#4223) and documentation link fixes (flame-engine#4234, flame-engine#4235).

The only conflict was in post_process_component.dart: the fork's own
lookup through CameraComponent.currentCamera is replaced by upstream's
walk over CameraComponent.currentCameras, and the camera import that
the upstream version no longer needs is dropped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

findPostProcessFromContext returns null for components rendered with CameraComponent.postProcess

3 participants