From 05533a7fd3bf761aa4fc3a753a4d13b68438410b Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Fri, 31 Oct 2025 16:53:08 +0800 Subject: [PATCH] Fix black bed texture if svg file (#11166) * Fix blank bed texture if svg file * Refresh scene once the texture compression is completed --- src/slic3r/GUI/GLCanvas3D.cpp | 1 + src/slic3r/GUI/GLTexture.cpp | 7 +++++++ src/slic3r/GUI/GLTexture.hpp | 7 ++++++- src/slic3r/GUI/PartPlate.cpp | 5 ++++- src/slic3r/Utils/FileHelp.cpp | 4 +--- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 86e29afb24..9a1d538b8f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3309,6 +3309,7 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt) bool imgui_requires_extra_frame = wxGetApp().imgui()->requires_extra_frame(); m_dirty |= imgui_requires_extra_frame; #endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT + m_dirty |= GLTexture::Compressor::has_compressed_texture_to_refresh(); if (!m_dirty) return; diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index bb3693e32a..75e383a381 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -101,6 +101,8 @@ void GLTexture::Compressor::send_compressed_data_to_gpu() this->reset(); } +std::atomic GLTexture::Compressor::m_dirty = false; + void GLTexture::Compressor::compress() { // reference: https://github.com/Cyan4973/RygsDXTc @@ -123,6 +125,11 @@ void GLTexture::Compressor::compress() level.src_data.clear(); ++ m_num_levels_compressed; } + + // Trigger an idle event to refresh the scene once the texture data is ready + // This fixes the issue that the bed texture is black after switching printer model until mouse moves to the 3d scene + m_dirty = true; + wxWakeUpIdle(); } GLTexture::Quad_UVs GLTexture::FullTextureUVs = { { 0.0f, 1.0f }, { 1.0f, 1.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f } }; diff --git a/src/slic3r/GUI/GLTexture.hpp b/src/slic3r/GUI/GLTexture.hpp index 41068a9fb7..1bb63651f0 100644 --- a/src/slic3r/GUI/GLTexture.hpp +++ b/src/slic3r/GUI/GLTexture.hpp @@ -16,6 +16,8 @@ namespace GUI { class GLTexture { + public: + class Compressor { struct Level @@ -39,6 +41,8 @@ namespace GUI { // This atomic also works as a memory barrier for synchronizing results of the worker thread with the calling thread. std::atomic m_num_levels_compressed; + static std::atomic m_dirty; + public: explicit Compressor(GLTexture& texture) : m_texture(texture), m_abort_compressing(false), m_num_levels_compressed(0) {} ~Compressor() { reset(); } @@ -53,11 +57,12 @@ namespace GUI { void send_compressed_data_to_gpu(); bool all_compressed_data_sent_to_gpu() const { return m_levels.empty(); } + static bool has_compressed_texture_to_refresh() { return m_dirty.exchange(false); } + private: void compress(); }; - public: enum ECompressionType : unsigned char { None, diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index c092c93c09..ba4a6045e0 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -39,6 +39,7 @@ #include "Tab.hpp" #include "format.hpp" #include "slic3r/GUI/GUI.hpp" +#include "slic3r/Utils/FileHelp.hpp" #include #include using boost::optional; @@ -5563,8 +5564,10 @@ void PartPlateList::update_logo_texture_filename(const std::string &texture_file if (!texture_filename.empty() && !check_texture(texture_filename)) { m_logo_texture_filename = ""; BOOST_LOG_TRIVIAL(error) << "Unable to load bed texture: " << texture_filename; - } else + } else { m_logo_texture_filename = texture_filename; + Utils::slash_to_back_slash(m_logo_texture_filename); + } } /*slice related functions*/ diff --git a/src/slic3r/Utils/FileHelp.cpp b/src/slic3r/Utils/FileHelp.cpp index 5189635d7b..bd67dab46f 100644 --- a/src/slic3r/Utils/FileHelp.cpp +++ b/src/slic3r/Utils/FileHelp.cpp @@ -1,7 +1,6 @@ #include "FileHelp.hpp" #include #include -#include namespace Slic3r { namespace Utils { @@ -20,8 +19,7 @@ bool is_file_too_large(std::string file_path, bool &try_ok) } void slash_to_back_slash(std::string &file_path) { - std::regex regex("\\\\"); - file_path = std::regex_replace(file_path, regex, "/"); + std::replace(file_path.begin(), file_path.end(), '\\', '/'); } }} // namespace Slic3r::Utils