-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Resizing camera target image causes Validation Error #5595
Comments
@zaycev I've had this issue as well. I looked into it a bit, but didn't find exactly what the problem is. A workaround I have currently is to manually send a |
Here is a minimal example that reproduces the problem on my machine: use bevy::{
prelude::*,
render::{
camera::RenderTarget,
render_resource::{
Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
},
},
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(FirstFrame(true))
.add_startup_system(setup)
.add_system(resize)
.run()
}
struct FirstFrame(bool);
struct RenderTexture(Handle<Image>);
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let size = Extent3d {
width: 512,
height: 512,
..default()
};
let mut image = Image {
texture_descriptor: TextureDescriptor {
label: None,
size,
dimension: TextureDimension::D2,
format: TextureFormat::Bgra8UnormSrgb,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::RENDER_ATTACHMENT,
},
..default()
};
image.resize(size);
let image_handle = images.add(image);
commands.spawn_bundle(Camera2dBundle {
camera: Camera {
target: RenderTarget::Image(image_handle.clone()),
..default()
},
..default()
});
commands.insert_resource(RenderTexture(image_handle));
}
fn resize(
mut first_frame: ResMut<FirstFrame>,
texture_handle: Res<RenderTexture>,
mut images: ResMut<Assets<Image>>,
) {
if first_frame.0 {
first_frame.0 = false;
} else {
if let Some(image) = images.get_mut(&texture_handle.0) {
image.resize(Extent3d {
width: 1024,
height: 1024,
..default()
});
}
}
} |
I think this was introduced by #4745. Before this change the physical size of the camera target was calculated directly in the On the surface this looks okay, however the The reason for this is that the The This also explains why the workaround posted by @DGriffin91 works. This work-around adds the event directly to the I think a better work-around would be to schedule app.add_system_to_stage(
CoreStage::PostUpdate,
Assets::<Image>::asset_event_system.before(CameraUpdateSystem),
); I am not sure what a correct fix for the problem would look like. |
I can confirm having just tried this that this workaround works Vrixyz@3f1cc36, getting a crash without the |
This appears to be fixed on main; can you try to reproduce there? |
Still present even with Bevy Asset v2. |
Since Bevy no longer crashes, I created a new issue with the updated description and minimal project to reproduce: #10665. |
Bevy version
0.8
[Optional] Relevant system information
What you did
Image
target.What went wrong
Panic due to validation error.
Additional information
Resizing code that causes error:
Workaround with despawning main camera:
The text was updated successfully, but these errors were encountered: