From ae7a284462652736120c4748150495c43e5afe6a Mon Sep 17 00:00:00 2001 From: b-guild Date: Wed, 6 Nov 2024 10:48:32 -0800 Subject: [PATCH 1/4] Preventing Grid from panicking for invalid row/column --- fyrox-ui/src/grid.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/fyrox-ui/src/grid.rs b/fyrox-ui/src/grid.rs index 31496bea4..cb625832b 100644 --- a/fyrox-ui/src/grid.rs +++ b/fyrox-ui/src/grid.rs @@ -25,8 +25,8 @@ use crate::{ core::{ - algebra::Vector2, math::Rect, pool::Handle, reflect::prelude::*, type_traits::prelude::*, - uuid_provider, variable::InheritableVariable, visitor::prelude::*, + algebra::Vector2, log::Log, math::Rect, pool::Handle, reflect::prelude::*, + type_traits::prelude::*, uuid_provider, variable::InheritableVariable, visitor::prelude::*, }, define_constructor, draw::{CommandTexture, Draw, DrawingContext}, @@ -456,8 +456,24 @@ impl Grid { let Some(node) = ui.try_get(*handle) else { continue; }; - let row = &mut rows[node.row()]; - let col = &mut cols[node.column()]; + let Some(row) = rows.get_mut(node.row()) else { + Log::err(format!( + "Node row out of bounds: {} row:{}, column:{}", + node.type_name(), + node.row(), + node.column() + )); + continue; + }; + let Some(col) = cols.get_mut(node.column()) else { + Log::err(format!( + "Node column out of bounds: {} row:{}, column:{}", + node.type_name(), + node.row(), + node.column() + )); + continue; + }; if col.size_mode == SizeMode::Auto { col.unmeasured_node_count += 1 } @@ -479,8 +495,12 @@ impl Grid { }; let mut rows = self.rows.borrow_mut(); let mut cols = self.columns.borrow_mut(); - let row = &mut rows[node.row()]; - let col = &mut cols[node.column()]; + let Some(row) = rows.get_mut(node.row()) else { + return; + }; + let Some(col) = cols.get_mut(node.column()) else { + return; + }; let constraint = Vector2::new( choose_constraint(col, available_size.x), choose_constraint(row, available_size.y), From 65cf32d31fae24d94bf921e8d8dc40c24a230852 Mon Sep 17 00:00:00 2001 From: b-guild Date: Wed, 6 Nov 2024 11:14:46 -0800 Subject: [PATCH 2/4] Removing Grid unmeasured_node_count from reflect and visit. --- fyrox-ui/src/grid.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fyrox-ui/src/grid.rs b/fyrox-ui/src/grid.rs index cb625832b..2dcdb5e4c 100644 --- a/fyrox-ui/src/grid.rs +++ b/fyrox-ui/src/grid.rs @@ -115,6 +115,8 @@ pub struct GridDimension { /// For Auto rows and columns this is initially the number of nodes in that row or column, /// and then it is reduced as nodes are measured. /// This is zero for all non-Auto rows and columns. + #[visit(skip)] + #[reflect(hidden)] unmeasured_node_count: usize, } From fc5c9ff154fa9d1000e244f63f8080a2850c2ef1 Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Wed, 6 Nov 2024 23:53:04 +0300 Subject: [PATCH 3/4] fixed crash when using `accurate_world_bounding_box` on some meshes - it would crash if a mesh has no position/bone indices/bone weights attributes in its vertex buffer --- fyrox-impl/src/scene/mesh/mod.rs | 34 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fyrox-impl/src/scene/mesh/mod.rs b/fyrox-impl/src/scene/mesh/mod.rs index 06ee7448c..eff731ba2 100644 --- a/fyrox-impl/src/scene/mesh/mod.rs +++ b/fyrox-impl/src/scene/mesh/mod.rs @@ -457,11 +457,13 @@ impl Mesh { let data = data.data_ref(); if surface.bones().is_empty() { for view in data.vertex_buffer.iter() { + let Ok(vertex_pos) = view.read_3_f32(VertexAttributeUsage::Position) else { + break; + }; + bounding_box.add_point( self.global_transform() - .transform_point(&Point3::from( - view.read_3_f32(VertexAttributeUsage::Position).unwrap(), - )) + .transform_point(&Point3::from(vertex_pos)) .coords, ); } @@ -481,20 +483,20 @@ impl Mesh { for view in data.vertex_buffer.iter() { let mut position = Vector3::default(); - for (&bone_index, &weight) in view - .read_4_u8(VertexAttributeUsage::BoneIndices) - .unwrap() - .iter() - .zip( - view.read_4_f32(VertexAttributeUsage::BoneWeight) - .unwrap() - .iter(), - ) - { + + let Ok(vertex_pos) = view.read_3_f32(VertexAttributeUsage::Position) else { + break; + }; + let Ok(bone_indices) = view.read_4_u8(VertexAttributeUsage::BoneIndices) else { + break; + }; + let Ok(bone_weights) = view.read_4_f32(VertexAttributeUsage::BoneWeight) else { + break; + }; + + for (&bone_index, &weight) in bone_indices.iter().zip(bone_weights.iter()) { position += bone_matrices[bone_index as usize] - .transform_point(&Point3::from( - view.read_3_f32(VertexAttributeUsage::Position).unwrap(), - )) + .transform_point(&Point3::from(vertex_pos)) .coords .scale(weight); } From f95d2cdd6d2837c2b196a9709683441c6793cf1f Mon Sep 17 00:00:00 2001 From: b-guild Date: Wed, 6 Nov 2024 13:09:58 -0800 Subject: [PATCH 4/4] Change tree column from auto to stretch --- fyrox-ui/src/tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fyrox-ui/src/tree.rs b/fyrox-ui/src/tree.rs index 32d370c79..97e084326 100644 --- a/fyrox-ui/src/tree.rs +++ b/fyrox-ui/src/tree.rs @@ -775,7 +775,7 @@ impl TreeBuilder { panel }), ) - .add_column(Column::auto()) + .add_column(Column::stretch()) .add_row(Row::strict(24.0)) .add_row(Row::stretch()) .build(ctx);