[flame_3d] Nested components are culled at their old position after an ancestor moves
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
What happened?
When the transform of a Component3D changes, its descendants keep using the AABB that was cached for their old world position, so they are frustum culled based on where they used to be.
Component3D._onTransformChanged propagates the world transform dirty flag down the subtree, but the AABB dirty flag is only propagated up (markAabbDirty walks the parents). The children's cached AABBs are never invalidated, so after an ancestor moves:
- a child that was out of view stays culled even when it is moved into view, and
- a child that was in view keeps being drawn (or tested) as if it was still in its old spot.
This affects regular MeshComponents and ModelComponents, not only custom Object3Ds, as long as they are nested under a Component3D that moves. Common examples are a group that is moved as a whole, or a character with attached meshes.
What do you expect?
When a component's transform changes, the cached AABBs of all of its descendants should be invalidated too, so that they are culled based on their current world position.
How can we reproduce this?
- Run the
main.dartbelow withflutter run --enable-flutter-gpu(on Windows also add--enable-impeller). - Two cubes should be visible after a second: the red one is a direct child of the world, the green one is a
MeshComponentinside aComponent3Dgroup that starts behind the camera and moves to the origin after one second. - Only the red cube is ever rendered. The green cube's AABB is still cached at its initial position behind the camera.
What steps should take to fix this?
Mark the AABB dirty together with the world transform when propagating down the subtree in Component3D._markWorldTransformDirty, and mark the parent's AABB dirty from _onTransformChanged (calling markAabbDirty() on the component itself would return early, since the downward propagation already marked it).
The early return in _markWorldTransformDirty should then only happen when both flags are already dirty. A component's world transform can be clean while its AABB is dirty and vice versa, so checking only one of them would stop the propagation too early.
Do have an example of where the bug occurs?
import 'package:flame/game.dart';
import 'package:flame_3d/camera.dart';
import 'package:flame_3d/components.dart';
import 'package:flame_3d/game.dart';
import 'package:flame_3d/graphics.dart';
import 'package:flame_3d/resources.dart';
import 'package:flutter/widgets.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await GpuBackend.initialize();
runApp(GameWidget(game: ReproGame()));
}
class ReproGame extends FlameGame3D {
ReproGame()
: super(
camera: CameraComponent3D(
position: Vector3(0, 2, -6),
target: Vector3(0, 1, 0),
),
);
@override
Future<void> onLoad() async {
world.addAll([
// Red: not nested, world position (1.5, 1, 0). Rendered.
MeshComponent(
mesh: _cubeMesh(const Color(0xFFFF0000)),
position: Vector3(1.5, 1, 0),
),
// Green: starts behind the camera. After one second its parent moves
// it to world position (-1.5, 1, 0). Never rendered.
MovingGroup(
children: [
MeshComponent(
mesh: _cubeMesh(const Color(0xFF00FF00)),
position: Vector3(-1.5, 1, 0),
),
],
),
]);
}
Mesh _cubeMesh(Color color) => CuboidMesh(
size: Vector3.all(1),
material: UnlitMaterial(albedoColor: color),
);
}
/// A plain group that starts behind the camera and moves to the origin after
/// one second.
class MovingGroup extends Component3D {
MovingGroup({super.children}) : super(position: Vector3(0, 0, -30));
double _elapsed = 0;
@override
void update(double dt) {
super.update(dt);
_elapsed += dt;
if (_elapsed > 1 && position.z != 0) {
position.setZero();
}
}
}
Relevant log output
No errors or warnings are logged.
Execute in a terminal and put output into the code block below
Flutter 3.47.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 737ba8f885 (6 days ago) • 2026-10-22 21:37:31 -0700
Engine • hash dfd2e6cb7d319db05e3bf1503f3e2ac60f6288a2 (revision cf636b1dfb) (6 days ago) • 2026-10-23 02:13:38.000Z
Tools • Dart 3.13.7 • DevTools 2.60.0
Affected platforms
All
Other information
Reproduced on Windows (Impeller with the OpenGL ES backend), but the culling logic is platform independent.
Nested transforms were introduced in #3867. The world transform matrix is updated correctly there, only the cached AABBs used for culling are not.
Are you interested in working on a PR for this?
- I want to work on this
- Lingua principale
- Dart
- Stelle
- 10.8k
- Fork
- 1.1k
- Merge medio
- 1g 21h
- PR unite (30g)
- 53
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di flame-engine/flame
-
`PostProcessSequentialGroup` skips earlier post processes when the subtree is rendered more than onceForse già presa @ufrshubham l’ha presa 1 giorno fa. Apertabug
flame-engine/flame#4193 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
`ComponentPool` returns components to the pool while they are still in use, and loses components removed before mountingForse già presa @ufrshubham l’ha presa 1 giorno fa. Apertabug
flame-engine/flame#4191 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
`PostProcessComponent` throws `StateError` when it has no `PositionComponent` childrenForse già presa @ufrshubham l’ha presa 2 giorni fa. Apertabug
flame-engine/flame#4182 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
flame-engine/flame#4176 ·
I maintainer di solito rispondono entro 1 giorno
-
discussion enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
flame-engine/flame#4175 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di flame-engine/flame
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
lollipopkit/flutter_server_box#1851 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
mikejr83/rc-soar-score#724 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ccch1mneyyy/dsh-Go#381 ·
I maintainer di solito rispondono entro 1 giorno
-
Broken links in the docsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
letsar/flutter_slidable#563 ·
I maintainer di solito rispondono entro 1 giorno
-
bot-found bug priority: P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
madenvel/KalinkaPlayer#498 ·