fixed panic when changing layers in the absm editor
@@ -331,12 +331,7 @@ impl StateViewer {
machine_layer: &MachineLayer,
editor_scene: &EditorScene,
) {
- if self.state.is_none() {
- return;
- }
-
- let parent_state_ref = &machine_layer.states()[self.state];
-
+ if let Some(parent_state_ref) = machine_layer.states().try_borrow(self.state) {
let mut views = ui
.node(self.canvas)
.children()
@@ -440,7 +435,11 @@ impl StateViewer {
send_sync_message(
ui,
- WidgetMessage::link(node_view, MessageDirection::ToWidget, self.canvas),
+ WidgetMessage::link(
+ node_view,
+ MessageDirection::ToWidget,
+ self.canvas,
+ ),
);
views.push(node_view);
@@ -495,7 +494,11 @@ impl StateViewer {
send_sync_message(
ui,
- AbsmNodeMessage::input_sockets(view, MessageDirection::ToWidget, input_sockets),
+ AbsmNodeMessage::input_sockets(
+ view,
+ MessageDirection::ToWidget,
+ input_sockets,
+ ),
);
}
@@ -572,7 +575,8 @@ impl StateViewer {
.unwrap();
let connection = ConnectionBuilder::new(
- WidgetBuilder::new().with_context_menu(self.connection_context_menu.menu),
+ WidgetBuilder::new()
+ .with_context_menu(self.connection_context_menu.menu),
)
.with_source_socket(source.base.output_socket)
.with_source_node(source.handle())
@@ -582,7 +586,11 @@ impl StateViewer {
send_sync_message(
ui,
- WidgetMessage::link(connection, MessageDirection::ToWidget, self.canvas),
+ WidgetMessage::link(
+ connection,
+ MessageDirection::ToWidget,
+ self.canvas,
+ ),
);
send_sync_message(
ui,
@@ -631,5 +639,11 @@ impl StateViewer {
MessageDirection::ToWidget,
),
);
+ } else {
+ // Clean the canvas.
+ for child in ui.node(self.canvas).children() {
+ ui.send_message(WidgetMessage::remove(*child, MessageDirection::ToWidget));
+ }
+ }
}
}
