Skip to content

Commit 31c7841

Browse files
Fix panic in FpsOverlay with disabled FrameTimeGraph (#20461)
# Objective I am getting the following panic on start: ``` thread 'main' panicked at /home/User/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wgpu-26.0.1/src/backend/wgpu_core.rs:1195:26: wgpu error: Validation Error Caused by: In Device::create_bind_group, label = 'FrametimeGraphMaterial' Buffer with '' label binding size is zero note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Encountered a panic in system `bevy_render::render_asset::prepare_assets<bevy_ui_render::ui_material_pipeline::PreparedUiMaterial<bevy_dev_tools::frame_time_graph::FrametimeGraphMaterial>>`! ``` when registering the `FpsOverlayPlugin` with the frame time graph disabled by default: ```rust app.add_plugins(FpsOverlayPlugin { config: FpsOverlayConfig { text_config: TextFont { font_size: 18.0, ..Default::default() }, frame_time_graph_config: FrameTimeGraphConfig { enabled: false, // causes panic above ..Default::default() }, enabled: false, ..Default::default() }, }) ``` ## Solution I went with the most pragmatic fix I could find, since I am no render/shader expert but I can imagine there is a better way to fix this, please let me know. My reasoning being: It does not panic after `update_frame_time_values` called `buffer.set_data(frame_times.clone().as_slice())`. So I ended up logging the buffer inside the system, and the first time it is called with empty `frame_times` it writes it into the `ShaderStorageBuffer` as `[0, 0, 0, 0]`. Doing the same when initializing the storage buffer fixes the panic on start. --------- Co-authored-by: James Liu <[email protected]>
1 parent dfd10f1 commit 31c7841

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/bevy_dev_tools/src/fps_overlay.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ fn setup(
189189
..Default::default()
190190
},
191191
MaterialNode::from(frame_time_graph_materials.add(FrametimeGraphMaterial {
192-
values: buffers.add(ShaderStorageBuffer::default()),
192+
values: buffers.add(ShaderStorageBuffer {
193+
// Initialize with dummy data because the default (`data: None`) will
194+
// cause a panic in the shader if the frame time graph is constructed
195+
// with `enabled: false`.
196+
data: Some(vec![0, 0, 0, 0]),
197+
..Default::default()
198+
}),
193199
config: FrameTimeGraphConfigUniform::new(
194200
overlay_config.frame_time_graph_config.target_fps,
195201
overlay_config.frame_time_graph_config.min_fps,

0 commit comments

Comments
 (0)