From 947c54d2e694e213a6e5cfb95616b2ffff3df3c6 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Sun, 12 Dec 2021 13:39:28 +0100 Subject: [PATCH] Enabled OpeNGL debugging fore Arch Liunx have already patch PrusaSlicer to work with tbb21: --- src/slic3r/GUI/3DScene.cpp | 7 +++-- src/slic3r/GUI/3DScene.hpp | 4 +-- src/slic3r/GUI/GCodeViewer.cpp | 52 ++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 94b1f31569..a012ffa798 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -44,8 +44,8 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char { #if defined(NDEBUG) // In release mode, only show OpenGL errors if sufficiently high loglevel. - if (Slic3r::get_logging_level() < 5) - return; +// if (Slic3r::get_logging_level() < 5) +// return; #endif // NDEBUG GLenum err = glGetError(); @@ -64,6 +64,9 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char } BOOST_LOG_TRIVIAL(error) << "OpenGL error in " << file_name << ":" << line << ", function " << function_name << "() : " << (int)err << " - " << sErr; assert(false); + std::ostringstream sline; + sline << "OpenGL error in " << file_name << ":" << line << ", function " << function_name << "() : " << (int)err << " - " << sErr; + MessageBoxA(NULL, "glsafe", sline.str().c_str(), MB_OK | MB_ICONERROR); } #endif // HAS_GLSAFE diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 6d82e3bb7c..b9708e5141 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -13,9 +13,9 @@ #include #include -#ifndef NDEBUG +//#ifndef NDEBUG #define HAS_GLSAFE -#endif // NDEBUG +//#endif // NDEBUG #ifdef HAS_GLSAFE extern void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name); diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 8f1990a573..5bcff1ff07 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2675,13 +2675,33 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GCODE_VIEWER_STATISTICS this #endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { + ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color, size_t icount) { + if (icount == 0) + MessageBoxA(NULL, "fuj", "fuj1", MB_OK | MB_ICONERROR); for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { const RenderPath& path = *it; // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. - assert(! path.sizes.empty()); - assert(! path.offsets.empty()); + assert(!path.sizes.empty()); + assert(!path.offsets.empty()); glsafe(::glUniform4fv(uniform_color, 1, static_cast(path.color.data()))); + if (path.sizes.size() != path.offsets.size()) + MessageBoxA(NULL, "fuj", "fuj2", MB_OK | MB_ICONERROR); + for (int i = 0; i < path.sizes.size(); ++i) { + if ((path.sizes[i] % 2) != 0) + MessageBoxA(NULL, "fuj", "fuj3", MB_OK | MB_ICONERROR); + if (path.sizes[i] == 0) + MessageBoxA(NULL, "fuj", "fuj4", MB_OK | MB_ICONERROR); +#if 1 + // in bytes + size_t start = path.offsets[i]; + // in bytes; sizes are in counts + size_t end = start + path.sizes[i] * sizeof(GLushort); + if (start >= icount * sizeof(GLushort)) + MessageBoxA(NULL, "fuj", "fuj5", MB_OK | MB_ICONERROR); + if (end > icount * sizeof(GLushort)) + MessageBoxA(NULL, "fuj", "fuj6", MB_OK | MB_ICONERROR); +#endif + } glsafe(::glMultiDrawElements(GL_LINES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); #if ENABLE_GCODE_VIEWER_STATISTICS ++m_statistics.gl_multi_lines_calls_count; @@ -2693,13 +2713,33 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GCODE_VIEWER_STATISTICS this #endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { + ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color, size_t icount) { + if (icount == 0) + MessageBoxA(NULL, "fuj", "fuj7", MB_OK | MB_ICONERROR); for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { const RenderPath& path = *it; // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. assert(! path.sizes.empty()); assert(! path.offsets.empty()); glsafe(::glUniform4fv(uniform_color, 1, static_cast(path.color.data()))); + if (path.sizes.size() != path.offsets.size()) + MessageBoxA(NULL, "fuj", "fuj8", MB_OK | MB_ICONERROR); + for (int i = 0; i < path.sizes.size(); ++i) { + if ((path.sizes[i] % 3) != 0) + MessageBoxA(NULL, "fuj", "fuj9", MB_OK | MB_ICONERROR); + if (path.sizes[i] == 0) + MessageBoxA(NULL, "fuj", "fuj10", MB_OK | MB_ICONERROR); +#if 1 + // in bytes + size_t start = path.offsets[i]; + // in bytes; sizes are in counts + size_t end = start + path.sizes[i] * sizeof(GLushort); + if (start >= icount * sizeof(GLushort)) + MessageBoxA(NULL, "fuj", "fuj11", MB_OK | MB_ICONERROR); + if (end > icount * sizeof(GLushort)) + MessageBoxA(NULL, "fuj", "fuj12", MB_OK | MB_ICONERROR); +#endif + } glsafe(::glMultiDrawElements(GL_TRIANGLES, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); #if ENABLE_GCODE_VIEWER_STATISTICS ++m_statistics.gl_multi_triangles_calls_count; @@ -2851,11 +2891,11 @@ void GCodeViewer::render_toolpaths() } case TBuffer::ERenderPrimitiveType::Line: { glsafe(::glLineWidth(static_cast(line_width(zoom)))); - render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); + render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color, i_buffer.count); break; } case TBuffer::ERenderPrimitiveType::Triangle: { - render_as_triangles(it_path, buffer.render_paths.end(), *shader, uniform_color); + render_as_triangles(it_path, buffer.render_paths.end(), *shader, uniform_color, i_buffer.count); break; } default: { break; }