Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault with VBO rendering on Qt 6 #4983

Closed
wants to merge 1 commit into from

Conversation

cjmayo
Copy link
Contributor

@cjmayo cjmayo commented Feb 12, 2024

Every time on opening a scad file, OpenSCAD dd2da9e built with Qt 6 using #4929 crashes. Compiling the same commit for Qt 5 works fine, as does using the legacy renderer on Qt 6.

Backtrace from opening examples/Basics/logo.scad:

Thread 1 "openscad" received signal SIGSEGV, Segmentation fault.
0x00007ffff5576895 in ?? () from /usr/lib64/libc.so.6
#0  0x00007ffff5576895 in  () at /usr/lib64/libc.so.6
#1  0x00005555564d66c4 in VertexData::getLastVertex(std::vector<signed char, std::allocator<signed char> >&) const (this=0x5555595cfb90, interleaved_buffer=std::vector of length 44, capacity 44 = {...}) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VertexArray.cc:21
#2  0x00005555564d7810 in VertexArray::createVertex(std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, Color4f const&, unsigned long, unsigned long, double, unsigned long, unsigned long, bool, bool, std::function<void (VertexArray&, std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, Color4f const&, unsigned long, unsigned long, double, unsigned long, unsigned long, bool, bool)> const&) (this=0x7fffffffa9e0, points=..., normals=..., color=..., active_point_index=0, primitive_index=0, z_offset=0, shape_size=100, shape_dimensions=3, outlines=false, mirror=false, vertex_callback=...) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VertexArray.cc:139
#3  0x00005555564f6fbc in VBORenderer::create_vertex(VertexArray&, Color4f const&, std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, std::array<Eigen::Matrix<double, 3, 1, 0, 3, 1>, 3ul> const&, unsigned long, unsigned long, double, unsigned long, unsigned long, bool, bool) const (this=0x55555904baf0, vertex_array=..., color=..., points=..., normals=..., active_point_index=0, primitive_index=0, z_offset=0, shape_size=100, shape_dimensions=3, outlines=false, mirror=false) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VBORenderer.cc:188
#4  0x00005555564f74c5 in VBORenderer::create_triangle(VertexArray&, Color4f const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, unsigned long, double, unsigned long, unsigned long, bool, bool) const (this=0x55555904baf0, vertex_array=..., color=..., p0=..., p1=..., p2=..., primitive_index=0, z_offset=0, shape_size=100, shape_dimensions=3, outlines=false, mirror=false) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VBORenderer.cc:226
#5  0x00005555564f853c in VBORenderer::create_surface(PolySet const&, VertexArray&, Renderer::csgmode_e, Eigen::Transform<double, 3, 2, 0> const&, Color4f const&) const (this=0x55555904baf0, ps=..., vertex_array=..., csgmode=Renderer::CSGMODE_NORMAL, m=..., color=...) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VBORenderer.cc:314
#6  0x0000555556534ee4 in OpenCSGRenderer::createCSGVBOProducts(CSGProducts const&, Renderer::shaderinfo_t const*, bool, bool) (this=0x55555904baf0, products=..., highlight_mode=false, background_mode=false) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/preview/OpenCSGRenderer.cc:187
#7  0x0000555556532e5c in OpenCSGRenderer::prepare(bool, bool, Renderer::shaderinfo_t const*) (this=0x55555904baf0, shaderinfo=0x0) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/preview/OpenCSGRenderer.cc:69
#8  0x00005555565045a6 in GLView::paintGL() (this=0x555557291d68) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/GLView.cc:172
#9  0x00005555565ebf8d in QGLView::paintGL() (this=0x555557291d40) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/gui/QGLView.cc:174
#10 0x00007ffff7674815 in  () at /usr/lib64/libQt6OpenGLWidgets.so.6
#11 0x00007ffff61dcc48 in QWidget::event(QEvent*) () at /usr/lib64/libQt6Widgets.so.6
#12 0x00007ffff617a2a1 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib64/libQt6Widgets.so.6
#13 0x00005555565bda0b in OpenSCADApp::notify(QObject*, QEvent*) (this=0x7fffffffca20, object=0x555557291d40, event=0x7fffffffb240) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/gui/OpenSCADApp.cc:57
#14 0x00007ffff4f62d78 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib64/libQt6Core.so.6
#15 0x00007ffff61d45e5 in QWidgetPrivate::sendPaintEvent(QRegion const&) () at /usr/lib64/libQt6Widgets.so.6
#16 0x00007ffff61d4fd1 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#17 0x00007ffff61d64a1 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#18 0x00007ffff61d4be4 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#19 0x00007ffff61d64a1 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#20 0x00007ffff61d4be4 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#21 0x00007ffff61d64a1 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#22 0x00007ffff61d62d6 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#23 0x00007ffff61d62d6 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#24 0x00007ffff61d4be4 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) () at /usr/lib64/libQt6Widgets.so.6
#25 0x00007ffff61e9a80 in QWidgetRepaintManager::paintAndFlush() () at /usr/lib64/libQt6Widgets.so.6
#26 0x00007ffff61dce18 in QWidget::event(QEvent*) () at /usr/lib64/libQt6Widgets.so.6
#27 0x00005555565799f7 in MainWindow::event(QEvent*) (this=0x555557347d00, event=0x5555580df1d0) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/gui/MainWindow.cc:1782
#28 0x00007ffff617a2a1 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib64/libQt6Widgets.so.6
#29 0x00005555565bda0b in OpenSCADApp::notify(QObject*, QEvent*) (this=0x7fffffffca20, object=0x555557347d00, event=0x5555580df1d0) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/gui/OpenSCADApp.cc:57
#30 0x00007ffff4f62d78 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib64/libQt6Core.so.6
#31 0x00007ffff4f667fe in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib64/libQt6Core.so.6
#32 0x00007ffff51e5733 in  () at /usr/lib64/libQt6Core.so.6
#33 0x00007ffff7ca84f2 in  () at /usr/lib64/libglib-2.0.so.0
#34 0x00007ffff7cab6a7 in  () at /usr/lib64/libglib-2.0.so.0
#35 0x00007ffff7cabccc in g_main_context_iteration () at /usr/lib64/libglib-2.0.so.0
#36 0x00007ffff51e50bc in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQt6Core.so.6
#37 0x00007ffff4f6f07b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib64/libQt6Core.so.6
#38 0x00007ffff4f6ab83 in QCoreApplication::exec() () at /usr/lib64/libQt6Core.so.6
#39 0x0000555555f4eda7 in gui(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, boost::filesystem::path const&, int, char**) (inputFiles=std::vector of length 1, capacity 1 = {...}, original_path=..., argc=1, argv=0x7fffffffd508) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/openscad.cc:860
#40 0x0000555555f52bb0 in main(int, char**) (argc=1, argv=0x7fffffffd508) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/openscad.cc:1248

I haven't got Qt built with debug symbols at this time. I can if it would be useful.

Qt 6.6.1 and building on Gentoo Linux with:

-DCLANG_TIDY=OFF -DENABLE_CAIRO=yes -DENABLE_EGL=ON -DENABLE_GLX=OFF -DENABLE_TBB=yes -DENABLE_TESTS=no -DEXPERIMENTAL=yes -DHEADLESS=no -DUSE_CCACHE=OFF -DUSE_GLAD=ON -DUSE_MIMALLOC=OFF -DUSE_QT6=yes -DENABLE_GAMEPAD=no -DENABLE_HIDAPI=yes -DENABLE_QTDBUS=yes -DENABLE_SPNAV=yes -DCMAKE_BUILD_TYPE=RelWithDebInfo

I am obtaining and building the dependencies myself (some more CMake patching for that):

opencsg 1.6.0
manifold 3b8282e1d5cd3d
sanitizers-cmake 3f0542e4e034
tbb 2021.9.0

and running on Wayland.

I'm not saying this is a suitable fix - I do not understand what the code is doing.
I just went to the final piece of code that is leading to the segfault and experimented with reverting its last major change 8b12a30 ("Performance fixes, add vertex options", 2020-11-29) to find something that compiles, doesn't crash and renders images that basically look OK.

@kintel
Copy link
Member

kintel commented Feb 13, 2024

This is very curious. If you have the opportunity to figure out what values were sent to memcpy() to make it crash, that would be awesome.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 13, 2024

Ah, memcpy was in my original -O2 backtrace but with values optimised out, I missed it wasn't in the -O0 above. With -Og:

#0  0x00007ffff5576895 in  () at /usr/lib64/libc.so.6
#1  0x0000555555c579e9 in memcpy (__len=4, __src=0xfffffffffffffffc, __dest=0x5555562e5ad8) at /usr/include/bits/string_fortified.h:29
#2  VertexData::getLastVertex(std::vector<signed char, std::allocator<signed char> >&) const (this=<optimized out>, interleaved_buffer=std::vector of length 44, capacity 44 = {...}) at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VertexArray.cc:21

@kintel
Copy link
Member

kintel commented Feb 22, 2024

@cjmayo I ran across a similar issue, which turned out to be an issue with OpenGL errors causing a shader compilation to fail, resulting in an avalanche of silent issues eventually crashing with exactly the same issue as this.

Could you try building with debug info and run OpenSCAD with --debug=all, and check if this happens?

if (OpenSCAD::debug != "") PRINTDB("add_shader_attributes bad points size = %d", points.size());

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 22, 2024

Yes with the above:

QGLView: GLAD: Loaded OpenGL 4.6
VertexArray: 309 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 311 : glBufferData(GL_ARRAY_BUFFER, 1478400, 0, GL_STATIC_DRAW)
VBORenderer: add_shader_attributes bad points size = 3
Segmentation fault (core dumped)

I have also tried #5005 on dd2da9e with Qt 6. This fixes the segfault with logo.scad and some other files. But with examples/Advanced/children.scad:

  1. Segfault with openscad examples/Advanced/children.scad - not every time though!
  2. If I then do openscad and open children.scad from File/Recent Files both Preview and Render work fine
  3. It works fine if I run examples/Advanced/children.scad in gdb

I can get at the core dump from 1. with coredumpctl and it looks much the same:

#0  0x00007f560f176895 in ??? () at /usr/lib64/libc.so.6
#1  0x0000564ed8e2495d in memcpy (__len=4, __src=0xfffffffffffffffc, __dest=0x564edc6bdef8)
    at /usr/include/bits/string_fortified.h:29
#2  VertexData::getLastVertex
    (this=<optimized out>, interleaved_buffer=std::vector of length 44, capacity 44 = {...})
    at openscad-dd2da9e2908e881af6cb1fe90306fe6004081cb6/src/glview/VertexArray.cc:21

--debug output:

$ openscad --debug=all examples/Advanced/children.scad
...
QGLView: GLAD: Loaded OpenGL 4.6
VertexArray: 295 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 297 : glBufferData(GL_ARRAY_BUFFER, 1584, 0, GL_STATIC_DRAW)
Segmentation fault (core dumped)

@kintel
Copy link
Member

kintel commented Feb 23, 2024

Thanks! This is still a bit puzzling. I still believe that some OpenGL operation prior to rendering is going wrong, but we don't have a single way of checking this in OpenSCAD, so there is one code path which didn't get that message and tries to read uninitialized memory.

In addition, some of the debug output probably goes to the GUI console and gets lost when it crashes.

Btw., does this crash only in GUI mode, or can you force the crash on the command-line as well?
e.g. smth. like this: openscad file.scad -o out.png

@kintel
Copy link
Member

kintel commented Feb 23, 2024

Also, could you try this? #5008

It doesn't really do much, but may avert the crash at the cost of not trying to enable a broken shader. I'm interested in any debug messages.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 23, 2024

With children.scad the command-line is working fine with dd2da9e + #5005 on Qt 6.

Then moved on to 2eb528b + #5008 on Qt 6.
No segfaults. A lot of "Warning: Shader not available" messages in the terminal and in the OpenSCAD console:

ERROR: OpenGL error: invalid operation (0x0502) in openscad-2eb528b2702f8e46c6100b79ada5c4526b43d904/src/glview/Renderer.cc:22
              glCompileShader(shader)

I added another PRINTDB:

--- a/src/glview/Renderer.cc
+++ b/src/glview/Renderer.cc
@@ -19,7 +19,10 @@ GLuint compileShader(const std::string& name) {
   GLuint shader = glCreateShader(GL_VERTEX_SHADER);
   auto *c_source = shader_source.c_str();
   glShaderSource(shader, 1, (const GLchar **)&c_source, nullptr);
-  IF_GL_CHECK(glCompileShader(shader)) return 0;
+  IF_GL_CHECK(glCompileShader(shader)) {
+    PRINTDB("OpenGL Program Check Compile Vertex Shader Error Source:\n%s", c_source);
+    return 0;
+  }
   GLint status;
   glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
   if (!status) {

and now with openscad --debug=all examples/Basics/logo.scad in the Console I get:

ERROR: OpenGL error: invalid operation (0x0502) in openscad-2eb528b2702f8e46c6100b79ada5c4526b43d904/src/glview/Renderer.cc:22
              glCompileShader(shader)

Renderer: OpenGL Program Check Compile Vertex Shader Error Source:
#version 110

uniform vec4 color1;        // face color
uniform vec4 color2;        // edge color
attribute vec3 barycentric; // barycentric form of vertex coord
                            // either [1,0,0], [0,1,0] or [0,0,1] under normal circumstances (no edges disabled)
varying vec3 vBC;           // varying barycentric coords
varying float shading;      // multiplied by color1. color2 is without lighting

void main(void) {
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  vBC = barycentric;
  vec3 normal, lightDir;
  normal = normalize(gl_NormalMatrix * gl_Normal);
  lightDir = normalize(vec3(gl_LightSource[0].position));
  shading = 0.2 + abs(dot(normal, lightDir));
}

OpenGL Error: Error compiling Preview shaders

and in the terminal:

QGLView: GLAD: Loaded OpenGL 4.6
Warning: Shader not available
VertexArray: 295 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 297 : glBufferData(GL_ARRAY_BUFFER, 1344000, 0, GL_STATIC_DRAW)
OpenCSGRenderer: 322 : glBindBuffer(GL_ARRAY_BUFFER, 0)
VertexArray: 186 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 188 : glBufferData(GL_ARRAY_BUFFER, 1344000, 0x55582870f650, GL_STATIC_DRAW)
VertexArray: 190 : glBindBuffer(GL_ARRAY_BUFFER, 0)
VertexArray: useElements() = 0, elements_size_ = 0
Warning: Shader not available

@gsohler
Copy link
Member

gsohler commented Feb 23, 2024 via email

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 23, 2024

email mangled that patch a bit! Anyway I think I understood and did:

--- a/src/gui/MainWindow.cc
+++ b/src/gui/MainWindow.cc
@@ -1395,15 +1395,6 @@ void MainWindow::compileCSG()
                                                 						    this->background_products);
 #endif
     }
-#endif
-#ifdef USE_LEGACY_RENDERERS
-    this->thrownTogetherRenderer = std::make_shared<LegacyThrownTogetherRenderer>(this->root_products,
-                                                                                  this->highlights_products,
-                                                                                  this->background_products);
-#else
-    this->thrownTogetherRenderer = std::make_shared<ThrownTogetherRenderer>(this->root_products,
-                                                                            this->highlights_products,
-                                                                            this->background_products);
 #endif
     LOG("Compile and preview finished.");
     renderStatistic.printRenderingTime();

But that didn't make any noticeable difference to the output with logo.scad I reported last. (no new problems either though).

@kintel
Copy link
Member

kintel commented Feb 23, 2024

@cjmayo Not sure why the shader compilation fails, but I'll update my shader compilation code to report errors better. Sometime today depending on how quickly I can do it.

@kintel
Copy link
Member

kintel commented Feb 23, 2024

@cjmayo Try #5008 now. #5005 was already merged to master.

There was a bug which I fixed, and the shader compiler should now output a better error message.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 24, 2024

With the updated #5008 in the Console:

Renderer: Renderer() start
Renderer: setColorScheme
ERROR: OpenGL error: invalid operation (0x0502) in openscad-2eb528b2702f8e46c6100b79ada5c4526b43d904/src/glview/Renderer.cc:84
              glLinkProgram(edgeshader_prog)

Renderer: Renderer() end
Renderer: Renderer() start
Renderer: setColorScheme
Renderer: Renderer() end

Terminal is identical.

I put a few more IF_GL_CHECKs in:

--- a/src/glview/Renderer.cc
+++ b/src/glview/Renderer.cc
@@ -79,8 +79,8 @@ void Renderer::setupShader() {
 
 
   auto edgeshader_prog = glCreateProgram();
-  glAttachShader(edgeshader_prog, vs);
-  glAttachShader(edgeshader_prog, fs);
+  IF_GL_CHECK(glAttachShader(edgeshader_prog, vs)) return;
+  IF_GL_CHECK(glAttachShader(edgeshader_prog, fs)) return;
   IF_GL_CHECK(glLinkProgram(edgeshader_prog)) return;
   GLint status;
   glGetProgramiv(edgeshader_prog, GL_LINK_STATUS, &status);

And get:

ERROR: OpenGL error: invalid operation (0x0502) in openscad-2eb528b2702f8e46c6100b79ada5c4526b43d904/src/glview/Renderer.cc:82
              glAttachShader(edgeshader_prog, vs)

@kintel
Copy link
Member

kintel commented Feb 24, 2024

I wonder if the GL error happens before the Renderer constructor is called.
Could you try inserting this at the start of Renderer::setupShader()?

  glCheckd("Renderer::setupShader()", __FILE__, __LINE__);

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 24, 2024

Yes:

Renderer: setColorScheme
system-gl: OpenGL error: invalid operation (0x0502) in openscad-2eb528b2702f8e46c6100b79ada5c4526b43d904/src/glview/Renderer.cc:65
              Renderer::setupShader()

@kintel
Copy link
Member

kintel commented Feb 24, 2024

Thanks, so something is going wrong earlier. It's hard to debug for me, but if you have the opportunity to sprinkle glCheckd("something", __FILE__, __LINE__); statements around trying to pin down the bad GL call, that would be awesome!

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 26, 2024

I can't find what is causing the initial OpenGL error. It seems to be before rendering, including Renderer::Renderer().

There doesn't need to be a model loaded. I can trigger it by clicking on the View/View All menu entry or moving a mouse over the qglview widget. That is at some point after MainWindow::MainWindow() and before MainWindow::viewAll() or QGLView::mouseMoveEvent()

@kintel
Copy link
Member

kintel commented Feb 27, 2024

I can try to remote-diagnose it, but need more info:
Could you post your cmake output, plus the output of Help->Library info?

@kintel
Copy link
Member

kintel commented Feb 27, 2024

I think the first step is to check if we can use OpenGL as initialized by Qt, basically https://doc.qt.io/qt-6/qopenglwidget.html#details

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 27, 2024

QGLView::initializeGL(), QGLView::paintGL() and QGLView::resizeGL() are all fine (I added some logging to the last two to make sure they were being executed).

It isn't Mesa driver-specific anyway as I have also forced the software driver with LIBGL_ALWAYS_SOFTWARE=1.

I'm not sure it is worth any more of our time trying to pinpoint this.

Just ignoring it seems to work for me:

--- a/src/glview/Renderer.cc
+++ b/src/glview/Renderer.cc
@@ -81,7 +81,7 @@ void Renderer::setupShader() {
   auto edgeshader_prog = glCreateProgram();
   glAttachShader(edgeshader_prog, vs);
   glAttachShader(edgeshader_prog, fs);
-  IF_GL_CHECK(glLinkProgram(edgeshader_prog)) return;
+  glLinkProgram(edgeshader_prog);
   GLint status;
   glGetProgramiv(edgeshader_prog, GL_LINK_STATUS, &status);
   if (!status) {
QGLView: GLAD: Loaded OpenGL 4.6
VertexArray: 295 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 297 : glBufferData(GL_ARRAY_BUFFER, 1478400, 0, GL_STATIC_DRAW)
OpenCSGRenderer: 322 : glBindBuffer(GL_ARRAY_BUFFER, 0)
VertexArray: 186 : glBindBuffer(GL_ARRAY_BUFFER, 3)
VertexArray: 188 : glBufferData(GL_ARRAY_BUFFER, 1478400, 0x5559a6a7dd00, GL_STATIC_DRAW)
VertexArray: 190 : glBindBuffer(GL_ARRAY_BUFFER, 0)
VertexArray: useElements() = 0, elements_size_ = 0
VertexArray: 295 : glBindBuffer(GL_ARRAY_BUFFER, 4)
VertexArray: 297 : glBufferData(GL_ARRAY_BUFFER, 52800, 0, GL_STATIC_DRAW)
OpenCSGRenderer: 322 : glBindBuffer(GL_ARRAY_BUFFER, 0)

Would this be OK? The status of the link operation is still being checked.

@kintel
Copy link
Member

kintel commented Feb 27, 2024

I think we can skip the GL error check on glLinkProgram(), considering we inspect the results afterwards.
If everything else works, you get the correct shaders etc., we can probably just leave it at that.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 27, 2024

I am not getting any error messages or noticing any artefacts.

Maybe there was an easy way to find the problem:

$ MESA_DEBUG=1 openscad
Mesa: error: GL_INVALID_OPERATION in glDrawBuffers(unsupported buffer GL_BACK_LEFT)

The only use of GL_BACK_LEFT I can find is:
https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/rhi/qrhigles2.cpp?h=6.6.2#n3168

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 28, 2024

Let's close, segmentation fault is fixed.

Qt Bug reported: https://bugreports.qt.io/browse/QTBUG-122819

PR for removing IF_GL_CHECK: #5023

@cjmayo cjmayo closed this Feb 28, 2024
@cjmayo cjmayo deleted the getlastvertex branch February 28, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants