You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you load asynchronous a font through the assert_server and directly use the font_handle, panic can happen if this is done in a regular system, after startup.
I have modified the text.rs to show the panic. Modification is that the commands and asset loading are not done at startup but on a specific frame number.
Here is the modified example:
use bevy::{
diagnostic::{Diagnostics,FrameTimeDiagnosticsPlugin},
prelude::*,};/// This example illustrates how to create text and update it in a system. It displays the current FPS in the upper left hand corner.fnmain(){App::build().add_default_plugins().add_plugin(FrameTimeDiagnosticsPlugin::default()).add_resource(1u32).add_system(setup.system()).add_system(text_update_system.system()).run();}fntext_update_system(diagnostics:Res<Diagnostics>,mutquery:Query<&mutText>){formut text in&mut query.iter(){ifletSome(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS){ifletSome(average) = fps.average(){
text.value = format!("FPS: {:.2}", average);}}}}constFRAME_SPAWN:u32 = 3;fnsetup(mutcommands:Commands,count:Res<u32>,asset_server:Res<AssetServer>){if*count <= FRAME_SPAWN{println!("FRAME {}",*count);if*count == FRAME_SPAWN{let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
commands
// 2d camera.spawn(UiCameraComponents::default())// texture.spawn(TextComponents{style:Style{align_self:AlignSelf::FlexEnd,
..Default::default()},text:Text{value:"FPS:".to_string(),font: font_handle,style:TextStyle{font_size:60.0,color:Color::WHITE,},},
..Default::default()});}
commands.insert_resource(*count + 1);}}
Here is the panic message :
thread 'Compute Task Pool (2)' panicked at 'called `Option::unwrap()` on a `None` value', crates/bevy_text/src/font_atlas_set.rs:53:42
The text was updated successfully, but these errors were encountered:
I think the issue is that some code in bevy_text and bevy_ui is doing fonts.get(font_handle).unwrap(), but because asset loading is asynchronous, the Assets is not yet filled with the associated font.
If you load asynchronous a font through the assert_server and directly use the font_handle, panic can happen if this is done in a regular system, after startup.
I have modified the text.rs to show the panic. Modification is that the commands and asset loading are not done at startup but on a specific frame number.
Here is the modified example:
Here is the panic message :
The text was updated successfully, but these errors were encountered: