Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query fails to find existing entity #10329

Closed
torsteingrindvik opened this issue Oct 31, 2023 · 8 comments
Closed

Query fails to find existing entity #10329

torsteingrindvik opened this issue Oct 31, 2023 · 8 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach

Comments

@torsteingrindvik
Copy link
Contributor

torsteingrindvik commented Oct 31, 2023

Bevy version

Latest main: d67fbd5

What you did

I have two systems added to render_app:

render_app.add_systems(
                Render,
                prepare_bind_groups.in_set(RenderSet::PrepareBindGroups),
            )
            .add_systems(Render, map_read.after(RenderSet::Render))

The summarized systems are as follows:

fn prepare_bind_groups(
    ...
    views: Query<
        (Entity, &RenderImage, &CameraIndex),
        (With<PackedFrameSender>, With<ActiveFrameSender>),
    >,
) {
    ...
    for (entity, render_image, camera_id) in &views {
        info!("Preparing bind group for entity={entity:?}");
        ...
   }
}
fn map_read(
    ...
    debug_query: Query<
        (
            Entity,
            Option<&CameraIndex>,
            Option<&RenderImageBindGroup>,
            Option<&PackedFrameSender>,
        ),
        With<ActiveFrameSender>,
    >,
) {
    if debug_query.is_empty() {
        info!("No entities marked active");
    }

What went wrong

I run my Bevy app and the query is populated (see Working logs below).
I stop my app and and I run it again (no code changes!), and the query is forever empty (see Not working logs) even though prepare_bind_groups finds the correct entity.

The working situation and the non-working situation happens about 50% of the time, but if it works it keeps working (until the app quits), and if it does not work it never works (i.e. then the query is always empty in map_read but prepare_bind_groups is ok).

I don't see a way for the query to be empty when prepare_bind_groups clearly finds the entity.
I even made all extra components (except the ActiveFrameSender marker) optional in order to debug the query, but still empty.

Working logs

INFO system{name="prepare_bind_groups"}:prepare{frame=50}:cam{segment=3 index=0}: Preparing bind group for entity=17v0
INFO system{name="map_read"}:send packed{frame=50}:cam{segment=3 index=0}: Sending 10368000 bytes

Not working logs

INFO system{name="prepare_bind_groups"}:prepare{frame=93}:cam{segment=3 index=0}: Preparing bind group for entity=17v0
INFO system{name="map_read"}:send packed{frame=93}: No entities marked active
@torsteingrindvik torsteingrindvik added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 31, 2023
@hymm
Copy link
Contributor

hymm commented Oct 31, 2023

Are you using main branch? 0.11.3 doesn't have a RenderSet::PrepareBindGroups

@torsteingrindvik
Copy link
Contributor Author

Are you using main branch? 0.11.3 doesn't have a RenderSet::PrepareBindGroups

Yes, latest main (I put a commit hash at the top)

@superdump
Copy link
Contributor

Hmm. The PrepareFlush should be run after PrepareBindGroups and before Render.

@superdump
Copy link
Contributor

(PrepareResources, PrepareResourcesFlush, PrepareBindGroups)

@torsteingrindvik
Copy link
Contributor Author

torsteingrindvik commented Nov 1, 2023

The bug has been flaky for me locally but I got it again this morning.

After fiddling a lot with Schedule and the hierarchy and dependency DAGs and trying to figure out if I could print them to .dot files (seems you can since petgraph is used) and trying to map NodeIds back to system names I tried something else.

I changed the render world's ScheduleBuildSettings to not have ambiguity_detection set to ignore, which printed out ~70 ambiguities for me (seems like there are quite a bit by default #1868).

One of my ambiguities was between my map_read system and things in the Cleanup render set.

At first I didn't see how that could be but then it dawned on me:

// before
app.add_systems(Render, map_read.after(RenderSet::Render))

// after
app.add_systems(Render, map_read.after(RenderSet::Render).before(RenderSet::Cleanup))

I haven't seen the problem since, and the ambiguity detection for map_read is gone.
I think this fixed it but I'll keep watching for this bug for a few days.

I'd love for someone to comment on whether my interpretation is correct:

Does system_foo.after(set) allow scheduling system_foo at any time within the frame as long as set is complete?

^-- If so it makes sense that in some cases the render world entities are gone by the time map_read runs.

@johnbchron
Copy link
Contributor

As far as I know it allows scheduling it anytime in the schedule (so in the Render schedule) after the .after(foo) run criteria.

@torsteingrindvik
Copy link
Contributor Author

As far as I know it allows scheduling it anytime in the schedule (so in the Render schedule) after the .after(foo) run criteria.

So since both RenderSet::Render and RenderSet::Cleanup are in the Render schedule, an .after(RenderSet::Render) on its own does not necessarily mean before RenderSet::Cleanup.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen S-User-Error This issue was caused by a mistake in the user's approach and removed S-Needs-Triage This issue needs to be labelled labels Nov 4, 2023
@alice-i-cecile
Copy link
Member

I think we can close this out as not directly actionable, although I really want this experience to improve in several ways.

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach
Projects
None yet
Development

No branches or pull requests

5 participants