Skip to content

Commit 13dcdba

Browse files
committed
use bevy default texture format if the surface is not yet available (#6233)
# Objective - Fix #6231 ## Solution - In case no supported format is found, try to use Bevy default instead of panicking
1 parent 7673db7 commit 13dcdba

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

crates/bevy_render/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub mod prelude {
3939
use globals::GlobalsPlugin;
4040
pub use once_cell;
4141
use prelude::ComputedVisibility;
42+
use wgpu::TextureFormat;
4243

4344
use crate::{
4445
camera::CameraPlugin,
@@ -48,7 +49,7 @@ use crate::{
4849
render_graph::RenderGraph,
4950
render_resource::{PipelineCache, Shader, ShaderLoader},
5051
renderer::{render_system, RenderInstance, RenderTextureFormat},
51-
texture::ImagePlugin,
52+
texture::{BevyDefault, ImagePlugin},
5253
view::{ViewPlugin, WindowRenderPlugin},
5354
};
5455
use bevy_app::{App, AppLabel, Plugin};
@@ -163,17 +164,20 @@ impl Plugin for RenderPlugin {
163164
&options,
164165
&request_adapter_options,
165166
));
166-
// `available_texture_formats` won't be empty, or else will panick in the former
167-
// `initialize_renderer` call.
168-
let first_available_texture_format = RenderTextureFormat(available_texture_formats[0]);
167+
let texture_format = RenderTextureFormat(
168+
available_texture_formats
169+
.get(0)
170+
.cloned()
171+
.unwrap_or_else(TextureFormat::bevy_default),
172+
);
169173
debug!("Configured wgpu adapter Limits: {:#?}", device.limits());
170174
debug!("Configured wgpu adapter Features: {:#?}", device.features());
171175
app.insert_resource(device.clone())
172176
.insert_resource(queue.clone())
173177
.insert_resource(adapter_info.clone())
174178
.insert_resource(render_adapter.clone())
175179
.insert_resource(available_texture_formats.clone())
176-
.insert_resource(first_available_texture_format.clone())
180+
.insert_resource(texture_format.clone())
177181
.init_resource::<ScratchMainWorld>()
178182
.register_type::<Frustum>()
179183
.register_type::<CubemapFrusta>();
@@ -217,7 +221,7 @@ impl Plugin for RenderPlugin {
217221
.insert_resource(queue)
218222
.insert_resource(render_adapter)
219223
.insert_resource(available_texture_formats)
220-
.insert_resource(first_available_texture_format)
224+
.insert_resource(texture_format)
221225
.insert_resource(adapter_info)
222226
.insert_resource(pipeline_cache)
223227
.insert_resource(asset_server);

crates/bevy_render/src/renderer/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct RenderInstance(pub Instance);
103103
pub struct RenderAdapterInfo(pub AdapterInfo);
104104

105105
/// The [`TextureFormat`](wgpu::TextureFormat) used for rendering.
106-
/// Initially it's the first element in `AvailableTextureFormats`.
106+
/// Initially it's the first element in `AvailableTextureFormats`, or Bevy default format.
107107
#[derive(Resource, Clone, Deref, DerefMut)]
108108
pub struct RenderTextureFormat(pub wgpu::TextureFormat);
109109

@@ -278,10 +278,6 @@ pub async fn initialize_renderer(
278278
let mut available_texture_formats = Vec::new();
279279
if let Some(s) = request_adapter_options.compatible_surface {
280280
available_texture_formats = s.get_supported_formats(&adapter);
281-
if available_texture_formats.is_empty() {
282-
info!("{:?}", adapter_info);
283-
panic!("No supported texture formats found!");
284-
}
285281
};
286282
let available_texture_formats = Arc::new(available_texture_formats);
287283
(

0 commit comments

Comments
 (0)