File orca-slicer-fix-asserts-wxwidgets.patch of Package orca-slicer

From 5689c195947a2ec6bb3351d968ae7cc2e5b2e6c5 Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Thu, 12 Dec 2024 21:22:30 +0000
Subject: [PATCH] Fix multiple assertion failures with wxWidgets 3.2.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
 src/slic3r/GUI/BBLTopbar.cpp                   | 4 ++--
 src/slic3r/GUI/CalibrationWizardPresetPage.cpp | 2 +-
 src/slic3r/GUI/MsgDialog.cpp                   | 4 ++--
 src/slic3r/GUI/Widgets/AMSControl.cpp          | 4 ++--
 src/slic3r/GUI/Widgets/DropDown.cpp            | 2 ++
 src/slic3r/GUI/Widgets/ProgressDialog.cpp      | 9 ++++-----
 src/slic3r/GUI/Widgets/SideTools.cpp           | 2 +-
 src/slic3r/GUI/Widgets/StateColor.cpp          | 2 --
 src/slic3r/GUI/wxExtensions.cpp                | 6 ++++++
 9 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/slic3r/GUI/BBLTopbar.cpp b/src/slic3r/GUI/BBLTopbar.cpp
index 0bf251d72..b4040222c 100644
--- a/src/slic3r/GUI/BBLTopbar.cpp
+++ b/src/slic3r/GUI/BBLTopbar.cpp
@@ -97,8 +97,8 @@ void BBLTopbarArt::DrawButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& i
     int textX = 0, textY = 0;
 
     const wxBitmap& bmp = item.GetState() & wxAUI_BUTTON_STATE_DISABLED
-        ? item.GetDisabledBitmap()
-        : item.GetBitmap();
+        ? item.GetDisabledBitmapFor(wnd)
+        : item.GetBitmapFor(wnd);
 
     const wxSize bmpSize = bmp.IsOk() ? bmp.GetScaledSize() : wxSize(0, 0);
 
diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp
index 482ce61a1..bd95b0d23 100644
--- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp
+++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp
@@ -766,7 +766,7 @@ void CalibrationPresetPage::create_page(wxWindow* parent)
     m_top_sizer->Add(m_selection_panel, 0);
     m_top_sizer->Add(m_filament_list_panel, 0);
     m_top_sizer->Add(m_ext_spool_panel, 0);
-    m_top_sizer->Add(m_pa_cali_method_combox, 0);
+    if (m_pa_cali_method_combox) m_top_sizer->Add(m_pa_cali_method_combox, 0);
     m_top_sizer->Add(m_custom_range_panel, 0);
     m_top_sizer->AddSpacer(FromDIP(15));
     m_top_sizer->Add(m_warning_panel, 0);
diff --git a/src/slic3r/GUI/MsgDialog.cpp b/src/slic3r/GUI/MsgDialog.cpp
index 3d67c5c2e..10a379efb 100644
--- a/src/slic3r/GUI/MsgDialog.cpp
+++ b/src/slic3r/GUI/MsgDialog.cpp
@@ -206,9 +206,9 @@ Button* MsgDialog::add_button(wxWindowID btn_id, bool set_focus /*= false*/, con
     bd->button = btn;
     bd->type   = type;
 
-    mb->id        = wxString::Format("%d", m_buttons.size());
+    mb->id        = wxString::Format("%zd", m_buttons.size());
     mb->buttondata = bd;
-    m_buttons[ wxString::Format("%d", m_buttons.size())] = mb;
+    m_buttons[ wxString::Format("%zd", m_buttons.size())] = mb;
     return btn;
 };
 
diff --git a/src/slic3r/GUI/Widgets/AMSControl.cpp b/src/slic3r/GUI/Widgets/AMSControl.cpp
index 0c8d306f4..4503ac95e 100644
--- a/src/slic3r/GUI/Widgets/AMSControl.cpp
+++ b/src/slic3r/GUI/Widgets/AMSControl.cpp
@@ -1839,11 +1839,11 @@ AmsCans::AmsCans(wxWindow *parent,AMSinfo info,  AMSModel model) : AmsCans()
 {
     m_bitmap_extra_framework = ScalableBitmap(this, "ams_extra_framework_mid", 140);
 
-    SetDoubleBuffered(true);
     m_ams_model = model;
     m_info      = info;
 
     wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, AMS_CANS_WINDOW_SIZE);
+    SetDoubleBuffered(true);
     create(parent);
     Bind(wxEVT_PAINT, &AmsCans::paintEvent, this);
 }
@@ -2848,7 +2848,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
     m_calibration_err_panel->SetBackgroundColour(AMS_CONTROL_WHITE_COLOUR);
     wxBoxSizer *sizer_err_calibration_h = new wxBoxSizer(wxHORIZONTAL);
     wxBoxSizer *sizer_err_calibration_v = new wxBoxSizer(wxVERTICAL);
-    m_hyperlink = new wxHyperlinkCtrl(m_calibration_err_panel, wxID_ANY, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
+    m_hyperlink = new wxHyperlinkCtrl(m_calibration_err_panel, wxID_ANY, " ", wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
     m_hyperlink->SetVisitedColour(wxColour(31, 142, 234));
     auto m_tip_calibration_err = new wxStaticText(m_calibration_err_panel, wxID_ANY, _L("A problem occurred during calibration. Click to view the solution."), wxDefaultPosition,
                                                   wxDefaultSize, 0);
diff --git a/src/slic3r/GUI/Widgets/DropDown.cpp b/src/slic3r/GUI/Widgets/DropDown.cpp
index ab48a27d2..a20886243 100644
--- a/src/slic3r/GUI/Widgets/DropDown.cpp
+++ b/src/slic3r/GUI/Widgets/DropDown.cpp
@@ -195,6 +195,8 @@ void DropDown::paintNow()
 
 static wxSize GetBmpSize(wxBitmap & bmp)
 {
+    if (!bmp.IsOk())
+        return wxSize();
 #ifdef __APPLE__
     return bmp.GetScaledSize();
 #else
diff --git a/src/slic3r/GUI/Widgets/ProgressDialog.cpp b/src/slic3r/GUI/Widgets/ProgressDialog.cpp
index f7841d260..cc8665bff 100644
--- a/src/slic3r/GUI/Widgets/ProgressDialog.cpp
+++ b/src/slic3r/GUI/Widgets/ProgressDialog.cpp
@@ -138,7 +138,7 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
 
     m_pdStyle = style;
 
-    if (!wxDialog::Create(m_parentTop, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, GetWindowStyle())) return false;
+    if (!wxDialog::Create(m_parentTop, wxID_ANY, title, wxDefaultPosition, GetBestSize(), GetWindowStyle())) return false;
     SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
 
     /* SetSize(DESIGN_RESOUTION_PROGRESS_SIZE);
@@ -269,8 +269,7 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
 
     SetSizer(m_sizer_main);
     Layout();
-    Fit();
-    Centre(wxCENTER_FRAME | wxBOTH);
+    //Centre(wxCENTER_FRAME | wxBOTH);
     DisableOtherWindows();
     FormatString(message);
 
@@ -881,13 +880,13 @@ void ProgressDialog::UpdateMessage(const wxString &newmsg)
         const wxSize sizeOld = m_msg->GetSize();
 
         FormatString(newmsg);
-        Fit();
+        //Fit();
         // m_msg->SetLabel(newmsg);
 
         if (m_msg->GetSize().x > sizeOld.x) {
             // Resize the dialog to fit its new, longer contents instead of
             // just truncating it.
-            Fit();
+            //Fit();
         }
 
         // allow the window to repaint:
diff --git a/src/slic3r/GUI/Widgets/SideTools.cpp b/src/slic3r/GUI/Widgets/SideTools.cpp
index 85e1a1f65..38203e0f6 100644
--- a/src/slic3r/GUI/Widgets/SideTools.cpp
+++ b/src/slic3r/GUI/Widgets/SideTools.cpp
@@ -326,7 +326,7 @@ SideTools::SideTools(wxWindow *parent, wxWindowID id, const wxPoint &pos, const
     wxBoxSizer* sizer_error_desc = new wxBoxSizer(wxHORIZONTAL);
     wxBoxSizer* sizer_extra_info = new wxBoxSizer(wxHORIZONTAL);
 
-    m_link_network_state = new wxHyperlinkCtrl(m_side_error_panel, wxID_ANY,_L("Check the status of current system services"),"",wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER_HORIZONTAL | wxST_ELLIPSIZE_END);
+    m_link_network_state = new wxHyperlinkCtrl(m_side_error_panel, wxID_ANY,_L("Check the status of current system services"),"",wxDefaultPosition,wxDefaultSize,wxALIGN_CENTER_HORIZONTAL | wxST_ELLIPSIZE_END | wxHL_ALIGN_CENTRE);
     m_link_network_state->SetMinSize(wxSize(FromDIP(220), -1));
     m_link_network_state->SetMaxSize(wxSize(FromDIP(220), -1));
     m_link_network_state->SetFont(::Label::Body_12);
diff --git a/src/slic3r/GUI/Widgets/StateColor.cpp b/src/slic3r/GUI/Widgets/StateColor.cpp
index f2e1b0702..f4a92e77a 100644
--- a/src/slic3r/GUI/Widgets/StateColor.cpp
+++ b/src/slic3r/GUI/Widgets/StateColor.cpp
@@ -186,7 +186,6 @@ inline wxColour darkModeColorFor2(wxColour const &color)
     if (!gDarkMode)
         return color;
     auto iter = gDarkColors.find(color);
-    wxASSERT(iter != gDarkColors.end());
     if (iter != gDarkColors.end()) return iter->second;
     return color;
 }
@@ -202,7 +201,6 @@ wxColour StateColor::lightModeColorFor(wxColour const &color)
 {
     static std::map<wxColour, wxColour> gLightColors = revert(gDarkColors);
     auto iter = gLightColors.find(color);
-    wxASSERT(iter != gLightColors.end());
     if (iter != gLightColors.end()) return iter->second;
     return color;
 }
diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp
index b542723e1..5ef5d709b 100644
--- a/src/slic3r/GUI/wxExtensions.cpp
+++ b/src/slic3r/GUI/wxExtensions.cpp
@@ -896,6 +896,8 @@ ScalableBitmap::ScalableBitmap( wxWindow *parent,
 
 wxSize ScalableBitmap::GetBmpSize() const
 {
+    if (!m_bmp.IsOk())
+        return wxSize();
 #ifdef __APPLE__
     return m_bmp.GetScaledSize();
 #else
@@ -905,6 +907,8 @@ wxSize ScalableBitmap::GetBmpSize() const
 
 int ScalableBitmap::GetBmpWidth() const
 {
+    if (!m_bmp.IsOk())
+        return 0;
 #ifdef __APPLE__
     return m_bmp.GetScaledWidth();
 #else
@@ -914,6 +918,8 @@ int ScalableBitmap::GetBmpWidth() const
 
 int ScalableBitmap::GetBmpHeight() const
 {
+    if (!m_bmp.IsOk())
+        return 0;
 #ifdef __APPLE__
     return m_bmp.GetScaledHeight();
 #else
-- 
2.47.1