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
Conversation
This is very curious. If you have the opportunity to figure out what values were sent to |
Ah, memcpy was in my original
|
@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 openscad/src/glview/VBORenderer.cc Line 176 in dc2a0d1
|
Yes with the above:
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:
I can get at the core dump from 1. with coredumpctl and it looks much the same:
|
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? |
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. |
With children.scad the command-line is working fine with dd2da9e + #5005 on Qt 6. Then moved on to 2eb528b + #5008 on Qt 6.
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
and in the terminal:
|
Hi Chris
can you try for a moment to comment initialization of the
thrown-Together-Renderer like so ?
it fixed the problems in my side.
diff --git a/src/gui/MainWindow.cc b/src/gui/MainWindow.cc
index 6baf61b1b..606c050ed 100644
--- a/src/gui/MainWindow.cc
+++ b/src/gui/MainWindow.cc
@@ -1409,13 +1409,13 @@ void MainWindow::compileCSG()
}
#endif
#ifdef USE_LEGACY_RENDERERS
- this->thrownTogetherRenderer =
std::make_shared<LegacyThrownTogetherRenderer>(this->root_products,
-
this->highlights_products,
-
this->background_products);
+// 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);
+// this->thrownTogetherRenderer =
std::make_shared<ThrownTogetherRenderer>(this->root_products,
+//
this->highlights_products,
+//
this->background_products);
#endif
LOG("Compile and preview finished.");
renderStatistic.printRenderingTime();
~
…On Fri, Feb 23, 2024 at 8:54 PM Chris Mayo ***@***.***> wrote:
With children.scad the command-line is working fine with dd2da9e
<dd2da9e>
+ #5005 <#5005> on Qt 6.
Then moved on to 2eb528b
<2eb528b>
+ #5008 <#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
—
Reply to this email directly, view it on GitHub
<#4983 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCO4MT2SIWIQXZYHYDISJ3YVDXYTAVCNFSM6AAAAABDFI272WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRRHEYDKMRVGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
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). |
@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. |
With the updated #5008 in the Console:
Terminal is identical. I put a few more --- 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:
|
I wonder if the GL error happens before the Renderer constructor is called.
|
Yes:
|
Thanks, so something is going wrong earlier. It's hard to debug for me, but if you have the opportunity to sprinkle |
I can't find what is causing the initial OpenGL error. It seems to be before rendering, including 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 |
I can try to remote-diagnose it, but need more info: |
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 |
It isn't Mesa driver-specific anyway as I have also forced the software driver with 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) {
Would this be OK? The status of the link operation is still being checked. |
I think we can skip the GL error check on glLinkProgram(), considering we inspect the results afterwards. |
I am not getting any error messages or noticing any artefacts. Maybe there was an easy way to find the problem:
The only use of |
Let's close, segmentation fault is fixed. Qt Bug reported: https://bugreports.qt.io/browse/QTBUG-122819 PR for removing |
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:
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.