Skip to content

Commit

Permalink
fixed crash when after switching from shape editing mode to some other
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Jun 20, 2024
1 parent 4d39a12 commit 8fde978
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
46 changes: 27 additions & 19 deletions editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,16 @@ impl Editor {

let mut processed = false;
if let Some(scene) = self.scenes.current_scene_entry_mut() {
if let Some(current_interaction_mode) = scene.current_interaction_mode {
processed |= scene
.interaction_modes
.get_mut(&current_interaction_mode)
.unwrap()
.on_hot_key(&hot_key, &mut *scene.controller, engine, &self.settings);
if let Some(current_interaction_mode) = scene
.current_interaction_mode
.and_then(|current_mode| scene.interaction_modes.get_mut(&current_mode))
{
processed |= current_interaction_mode.on_hot_key(
&hot_key,
&mut *scene.controller,
engine,
&self.settings,
);
}
}

Expand Down Expand Up @@ -1299,17 +1303,18 @@ impl Editor {
self.navmesh_panel
.handle_message(message, &current_scene_entry.selection);

if let Some(current_im) = current_scene_entry.current_interaction_mode {
current_scene_entry
.interaction_modes
.get_mut(&current_im)
.unwrap()
.handle_ui_message(
message,
&current_scene_entry.selection,
game_scene,
engine,
);
if let Some(interaction_mode) = current_scene_entry
.current_interaction_mode
.and_then(|current_mode| {
current_scene_entry.interaction_modes.get_mut(&current_mode)
})
{
interaction_mode.handle_ui_message(
message,
&current_scene_entry.selection,
game_scene,
engine,
);
}

self.scene_node_context_menu.borrow_mut().handle_ui_message(
Expand Down Expand Up @@ -2547,8 +2552,11 @@ impl Editor {
);
}

if let Some(mode) = entry.current_interaction_mode {
entry.interaction_modes.get_mut(&mode).unwrap().update(
if let Some(interaction_mode) = entry
.current_interaction_mode
.and_then(|current_mode| entry.interaction_modes.get_mut(&current_mode))
{
interaction_mode.update(
&entry.selection,
&mut **controller,
&mut self.engine,
Expand Down
20 changes: 10 additions & 10 deletions editor/src/scene/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,21 @@ impl EditorSceneEntry {
pub fn set_interaction_mode(&mut self, engine: &mut Engine, mode: Option<Uuid>) {
if self.current_interaction_mode != mode {
// Deactivate current first.
if let Some(current_mode) = self.current_interaction_mode {
self.interaction_modes
.get_mut(&current_mode)
.unwrap()
.deactivate(&*self.controller, engine);
if let Some(interaction_mode) = self
.current_interaction_mode
.and_then(|current_mode| self.interaction_modes.get_mut(&current_mode))
{
interaction_mode.deactivate(&*self.controller, engine);
}

self.current_interaction_mode = mode;

// Activate new.
if let Some(current_mode) = self.current_interaction_mode {
self.interaction_modes
.get_mut(&current_mode)
.unwrap()
.activate(&*self.controller, engine);
if let Some(interaction_mode) = self
.current_interaction_mode
.and_then(|current_mode| self.interaction_modes.get_mut(&current_mode))
{
interaction_mode.activate(&*self.controller, engine);
}
}
}
Expand Down

0 comments on commit 8fde978

Please sign in to comment.