Skip to content

Commit

Permalink
Fix painter gizmos crash on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Nov 6, 2023
1 parent 28e2995 commit e57f68a
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 25 deletions.
11 changes: 0 additions & 11 deletions src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,6 @@ void GLMmSegmentationGizmo3DScene::release_geometry() {
glsafe(::glDeleteBuffers(1, &triangle_indices_VBO_id));
triangle_indices_VBO_id = 0;
}
if (this->vertices_VAO_id) {
glsafe(::glDeleteVertexArrays(1, &this->vertices_VAO_id));
this->vertices_VAO_id = 0;
}

this->clear();
}
Expand All @@ -933,7 +929,6 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const
if (shader == nullptr)
return;

glsafe(::glBindVertexArray(this->vertices_VAO_id));
// the following binding is needed to set the vertex attributes
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id));
const GLint position_id = shader->get_attrib_location("v_position");
Expand All @@ -954,24 +949,18 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const
glsafe(::glDisableVertexAttribArray(position_id));

glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindVertexArray(0));
}

void GLMmSegmentationGizmo3DScene::finalize_vertices()
{
assert(this->vertices_VAO_id == 0);
assert(this->vertices_VBO_id == 0);
if (!this->vertices.empty()) {
glsafe(::glGenVertexArrays(1, &this->vertices_VAO_id));
glsafe(::glBindVertexArray(this->vertices_VAO_id));

glsafe(::glGenBuffers(1, &this->vertices_VBO_id));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id));
glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(float), this->vertices.data(), GL_STATIC_DRAW));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
this->vertices.clear();

glsafe(::glBindVertexArray(0));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class GLMmSegmentationGizmo3DScene

// IDs of the Vertex Array Objects, into which the geometry has been loaded.
// Zero if the VBOs are not sent to GPU yet.
unsigned int vertices_VAO_id{ 0 };
unsigned int vertices_VBO_id{0};
std::vector<unsigned int> triangle_indices_VBO_ids;
};
Expand Down
11 changes: 0 additions & 11 deletions src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,6 @@ void TriangleSelectorPatch::render(int triangle_indices_idx)
if (shader == nullptr)
return;

glsafe(::glBindVertexArray(this->m_vertices_VAO_ids[triangle_indices_idx]));
// the following binding is needed to set the vertex attributes
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->m_vertices_VBO_ids[triangle_indices_idx]));
const GLint position_id = shader->get_attrib_location("v_position");
Expand All @@ -1529,7 +1528,6 @@ void TriangleSelectorPatch::render(int triangle_indices_idx)
glsafe(::glDisableVertexAttribArray(position_id));

glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindVertexArray(0));
}

void TriangleSelectorPatch::release_geometry()
Expand All @@ -1542,10 +1540,6 @@ void TriangleSelectorPatch::release_geometry()
glsafe(::glDeleteBuffers(1, &vertice_VBO_id));
vertice_VBO_id = 0;
}
for (auto &vertice_VAO_id : m_vertices_VAO_ids) {
glsafe(::glDeleteVertexArrays(1, &vertice_VAO_id));
vertice_VAO_id = 0;
}
for (auto& triangle_indices_VBO_id : m_triangle_indices_VBO_ids) {
glsafe(::glDeleteBuffers(1, &triangle_indices_VBO_id));
triangle_indices_VBO_id = 0;
Expand All @@ -1570,17 +1564,13 @@ void TriangleSelectorPatch::finalize_vertices()
void TriangleSelectorPatch::finalize_triangle_indices()
{
m_vertices_VBO_ids.resize(m_triangle_patches.size());
m_vertices_VAO_ids.resize(m_triangle_patches.size());
m_triangle_indices_VBO_ids.resize(m_triangle_patches.size());
m_triangle_indices_sizes.resize(m_triangle_patches.size());
assert(std::all_of(m_triangle_indices_VBO_ids.cbegin(), m_triangle_indices_VBO_ids.cend(), [](const auto& ti_VBO_id) { return ti_VBO_id == 0; }));

for (size_t buffer_idx = 0; buffer_idx < m_triangle_patches.size(); ++buffer_idx) {
std::vector<float>& patch_vertices = m_triangle_patches[buffer_idx].patch_vertices;
if (!patch_vertices.empty()) {
glsafe(::glGenVertexArrays(1, &m_vertices_VAO_ids[buffer_idx]));
glsafe(::glBindVertexArray(m_vertices_VAO_ids[buffer_idx]));

glsafe(::glGenBuffers(1, &m_vertices_VBO_ids[buffer_idx]));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vertices_VBO_ids[buffer_idx]));
glsafe(::glBufferData(GL_ARRAY_BUFFER, patch_vertices.size() * sizeof(float), patch_vertices.data(), GL_STATIC_DRAW));
Expand All @@ -1599,7 +1589,6 @@ void TriangleSelectorPatch::finalize_triangle_indices()
//BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: buffer_idx %2%, vertices size %3%, buffer id %4%")%__LINE__%buffer_idx%triangle_indices.size()%m_triangle_indices_VBO_ids[buffer_idx];
triangle_indices.clear();
}
glsafe(::glBindVertexArray(0));
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class TriangleSelectorPatch : public TriangleSelectorGUI {
void clear()
{
// BBS
this->m_vertices_VAO_ids.clear();
this->m_vertices_VBO_ids.clear();
this->m_triangle_indices_VBO_ids.clear();
this->m_triangle_indices_sizes.clear();
Expand Down Expand Up @@ -167,7 +166,6 @@ class TriangleSelectorPatch : public TriangleSelectorGUI {
// IDs of the Vertex Array Objects, into which the geometry has been loaded.
// Zero if the VBOs are not sent to GPU yet.
//unsigned int m_vertices_VBO_id{ 0 };
std::vector<unsigned int> m_vertices_VAO_ids;
std::vector<unsigned int> m_vertices_VBO_ids;
std::vector<unsigned int> m_triangle_indices_VBO_ids;

Expand Down

0 comments on commit e57f68a

Please sign in to comment.