From 78f002cee8fc23b4bd8b7ea36a45461c9613cb0a Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 12 Sep 2022 16:57:28 +0200 Subject: [PATCH] Limit count of thread generating preview image of font (Limitation of opened files on Linux) --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 26 ++++++++++++------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 5 +++- .../GUI/Jobs/CreateFontNameImageJob.cpp | 2 ++ .../GUI/Jobs/CreateFontNameImageJob.hpp | 4 +++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 322eb67c39..5581881899 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1307,7 +1307,10 @@ void GLGizmoEmboss::draw_font_list() size_t index = &face_name - &m_face_names.names.front(); ImGui::PushID(index); bool is_selected = (actual_face_name == face_name); - if (ImGui::Selectable(m_face_names.names_truncated[index].c_str(), is_selected)) { + ImVec2 selectable_size(0, m_gui_cfg->face_name_size.y()); + ImGuiSelectableFlags flags = 0; + if (ImGui::Selectable(m_face_names.names_truncated[index].c_str(), + is_selected, flags, selectable_size)) { if (!select_facename(face_name)) { del_facename = face_name; wxMessageBox(GUI::format( @@ -1317,8 +1320,15 @@ void GLGizmoEmboss::draw_font_list() if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", face_name.ToUTF8().data()); if (is_selected) ImGui::SetItemDefaultFocus(); - if (!m_face_names.exist_textures[index] && - ImGui::IsItemVisible()) { + if (m_face_names.exist_textures[index]) { + ImGui::SameLine(m_gui_cfg->face_name_max_width); + ImVec2 size(m_gui_cfg->face_name_size.x(), + m_gui_cfg->face_name_size.y()), + uv0(0.f, index / (float) m_face_names.names.size()), + uv1(1.f, (index + 1) / (float) m_face_names.names.size()); + ImGui::Image(tex_id, size, uv0, uv1); + } else if (ImGui::IsItemVisible() && m_count_opened_font_files < 10) { + ++m_count_opened_font_files; m_face_names.exist_textures[index] = true; std::string text = m_text.empty() ? "AaBbCc" : m_text; @@ -1337,17 +1347,13 @@ void GLGizmoEmboss::draw_font_list() gray_level, format, type, - level}; + level, + &m_count_opened_font_files }; auto job = std::make_unique(std::move(data)); auto& worker = wxGetApp().plater()->get_ui_job_worker(); queue_job(worker, std::move(job)); } - ImGui::SameLine(m_gui_cfg->face_name_max_width); - ImVec2 size(m_gui_cfg->face_name_size.x(), - m_gui_cfg->face_name_size.y()), - uv0(0.f, index / (float) m_face_names.names.size()), - uv1(1.f, (index + 1) / (float) m_face_names.names.size()); - ImGui::Image(tex_id, size, uv0, uv1); + ImGui::PopID(); } #ifdef SHOW_FONT_COUNT diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 8af94ec753..c76152276c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -246,8 +246,11 @@ private: // cancel for previous update of volume to cancel finalize part std::shared_ptr> m_update_job_cancel; - // cancel for rendering font name + // cancel for rendering font name after close comboBox bool m_allow_update_rendered_font; + // protection for open too much font files together + // Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/Yaru/48x48/status/image-missing.png: Error opening file /usr/share/icons/Yaru/48x48/status/image-missing.png: Too many open files (g-io-error-quark, 31) + unsigned int m_count_opened_font_files = 0; // Rotation gizmo GLGizmoRotate m_rotate_gizmo; diff --git a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp index 0338051378..98dc3121a8 100644 --- a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp +++ b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp @@ -94,6 +94,8 @@ void CreateFontImageJob::process(Ctl &ctl) void CreateFontImageJob::finalize(bool canceled, std::exception_ptr &) { + if (m_input.count_opened_font_files) + --(*m_input.count_opened_font_files); if (canceled) return; if (! (* m_input.allow_update)) return; diff --git a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp index 2eef33017f..5f730093cf 100644 --- a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp +++ b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.hpp @@ -39,6 +39,10 @@ struct FontImageData // texture meta data GLenum format = GL_ALPHA, type = GL_UNSIGNED_BYTE; GLint level = 0; + + // prevent opening too much files + // it is decreased in finalize phase + unsigned int *count_opened_font_files = nullptr; }; ///