From 8bd19d62b114714568ffee91561311d57ce6826e Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 24 Apr 2020 00:50:16 -0400 Subject: [PATCH] Fix panic with dragging into the same loadout slot --- common/src/comp/inventory/slot.rs | 8 ++++++++ voxygen/src/ui/widgets/ghost_image.rs | 2 +- voxygen/src/ui/widgets/slot.rs | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/src/comp/inventory/slot.rs b/common/src/comp/inventory/slot.rs index b7d6f27842..276c464402 100644 --- a/common/src/comp/inventory/slot.rs +++ b/common/src/comp/inventory/slot.rs @@ -1,5 +1,6 @@ use crate::{comp, comp::item}; use comp::{Inventory, Loadout}; +use log::warn; #[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)] pub enum Slot { @@ -169,6 +170,13 @@ fn swap_inventory_loadout( } fn swap_loadout(slot_a: EquipSlot, slot_b: EquipSlot, loadout: &mut Loadout) { + // Ensure that the slots are not the same (somehow the voxygen does this + // occasionsally) + if slot_a == slot_b { + warn!("Tried to swap equip slot with itself"); + return; + } + // Get items from the slots let item_a = loadout_remove(slot_a, loadout); let item_b = loadout_remove(slot_b, loadout); diff --git a/voxygen/src/ui/widgets/ghost_image.rs b/voxygen/src/ui/widgets/ghost_image.rs index 4ee1eb6010..cc47c6adaa 100644 --- a/voxygen/src/ui/widgets/ghost_image.rs +++ b/voxygen/src/ui/widgets/ghost_image.rs @@ -8,7 +8,7 @@ use conrod_core::{ }; /// This widget is like conrod's `Image` widget except it always returns false -/// for is_over +/// for is_over so widgets under it are still interactable #[derive(WidgetCommon)] pub struct GhostImage { #[conrod(common_builder)] diff --git a/voxygen/src/ui/widgets/slot.rs b/voxygen/src/ui/widgets/slot.rs index d45bbb5e20..78a7d79260 100644 --- a/voxygen/src/ui/widgets/slot.rs +++ b/voxygen/src/ui/widgets/slot.rs @@ -166,7 +166,11 @@ where self.events.push(Event::Dropped(*slot)); } else if let Some(idx) = slot_ids.iter().position(|slot_id| *slot_id == id) { // If widget is a slot widget swap with it - self.events.push(Event::Dragged(*slot, slots[idx])); + let (from, to) = (*slot, slots[idx]); + // Don't drag if it is the same slot + if from != to { + self.events.push(Event::Dragged(from, to)); + } } } // Mouse released stop dragging