From aa0737fa5ef2cf3ecbaecd74c3ac80f1fb77aaaa Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Thu, 7 Mar 2019 10:08:21 +0100
Subject: [PATCH] Fixed assert after try to add Part to Object with several
 Instances from the ObjectList.

+ Fixed selection on the 3DScene before a context menu showing
---
 src/slic3r/GUI/GLCanvas3D.cpp     | 10 +++++++---
 src/slic3r/GUI/GUI_ObjectList.cpp |  7 +++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp
index 0e5ee1991..8415e8c24 100644
--- a/src/slic3r/GUI/GLCanvas3D.cpp
+++ b/src/slic3r/GUI/GLCanvas3D.cpp
@@ -5308,14 +5308,18 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
                          && m_gizmos.get_current_type() != Gizmos::SlaSupports)  // disable context menu when the gizmo is open
                         {
                             // forces the selection of the volume
-                            if (!m_selection.is_multiple_full_instance())
+                            /** #ys_FIXME_to_delete after testing:
+                              * Next condition allows a multiple instance selection for the context menu,
+                              * which has no reason. So it's commented till next testing
+                              */
+//                             if (!m_selection.is_multiple_full_instance()) // #ys_FIXME_to_delete
                                 m_selection.add(m_hover_volume_id);
                             m_gizmos.update_on_off_state(m_selection);
                             post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT));
                             _update_gizmos_data();
                             wxGetApp().obj_manipul()->update_settings_value(m_selection);
-//                            // forces a frame render to update the view before the context menu is shown
-//                            render();
+                           // forces a frame render to update the view before the context menu is shown
+                           render();
                             
                             Vec2d logical_pos = pos.cast<double>();
 #if ENABLE_RETINA_GL
diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp
index 44998c14f..a4ce8fe12 100644
--- a/src/slic3r/GUI/GUI_ObjectList.cpp
+++ b/src/slic3r/GUI/GUI_ObjectList.cpp
@@ -1256,8 +1256,11 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode
 
     const GLCanvas3D::Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
     assert(obj_idx == selection.get_object_idx());
-    // Selected instance index in ModelObject. Only valid if there is only one instance selected in the selection.
-    int instance_idx = selection.get_instance_idx();
+
+    /** Any changes of the Object's composition is duplicated for all Object's Instances
+      * So, It's enough to take a bounding box of a first selected Instance and calculate Part(generic_subobject) position
+      */
+    int instance_idx = *selection.get_instance_idxs().begin();
     assert(instance_idx != -1);
     if (instance_idx == -1)
         return;