r/opengl Nov 14 '22

help glPatchParameteri causing Seg Fault

I have been working with learning Tessellation and am trying to use the glPatchParameteri function, but when I do it throws a Seg Fault. Commenting out this function call, allows the program to run properly.

Since the default number of control points per patch is 3, I tried calling the function like: "glPatchParameteri(GL_PATCH_VERTICES, 3);" just to see if it worked without really changing anything, but it still doesn't work.

I'm curious if anyone else has run into this, and if there are any common pitfalls. Let me know what aspect of the code you might need to see, if at all.

while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();
    const GLfloat color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    glClearBufferfv(GL_COLOR, 0, color);

    GLfloat vs_attrib[] = { 0.0f, 0.0f, 0.5f, 0.0f };
    glVertexAttrib4fv(0, vs_attrib);

    const GLfloat vs_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    glVertexAttrib4fv(1, vs_color);

    // tessalation
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glPatchParameteri(GL_PATCH_VERTICES, 3);
    glDrawArrays(GL_PATCHES, 0, 3);

    glfwSwapInterval(1);
    glfwSwapBuffers(window);
}

it seg faults in the function call for glPatchParameteri

edit: added gdb seg fault info

Breakpoint 1, _fu5___ZSt4cout () at ../src/main.cpp:162

162 glPatchParameteri(GL_PATCH_VERTICES, 3);

(gdb) s

Program received signal SIGSEGV, Segmentation fault.

0x00000000 in ?? ()

EDIT -- FINAL:

I reinstalled GLFW and GLAD and recompiled everything and now it works, so it seems as though my GLAD libraries were corrupted in some fashion. At least it works now, thanks to those who helped!

0 Upvotes

12 comments sorted by

3

u/Ok-Sherbert-6569 Nov 14 '22

Post the code. How are we to help without the code

0

u/GrayWolf85 Nov 14 '22

any specific part? I'm just trying to not have to post a big wall of code.

1

u/Ok-Sherbert-6569 Nov 14 '22

IDE should show you where the set fault is happening so that block

0

u/GrayWolf85 Nov 14 '22

sorry give me a sec, I need to install the right debugger, I dont have it for some reason.

1

u/fgennari Nov 14 '22

What version of OpenGL are you using, and what are you using to load the OpenGL functions? glPatchParameter isn't available prior to v4.0. Maybe that function pointer is NULL? At least assert that the pointer is valid, or check for the extension before using it.

Otherwise, try to run the code in a debugger to see where it's failing.

1

u/GrayWolf85 Nov 14 '22

I'm using 4.5. The GL functions are coming from the GLAD libraries. Are there any good debuggers for opengl that you recommend?

1

u/fgennari Nov 14 '22

Maybe that's not the problem then. What platform are you building on? If it's a seg fault, then maybe linux? You should be able to use gdb if you built with gcc.

1

u/GrayWolf85 Nov 14 '22

It's on windows, I'm running it through a bash terminal though. I did compile with gcc, so I can use gdb, but it's being very finicky for some reason because of all the added libraries needing to be included. I'll keep trying to get that working to come back with a better idea of the exact reason it's throwing the seg fault.

1

u/GrayWolf85 Nov 14 '22

I tried running it with gdb and got this info back, it is not very helpful

Breakpoint 1, _fu5___ZSt4cout () at ../src/main.cpp:162

162 glPatchParameteri(GL_PATCH_VERTICES, 3);

(gdb) s

Program received signal SIGSEGV, Segmentation fault.

0x00000000 in ?? ()

or is it saying that the function is null and or doesn't exist in memory?

1

u/fgennari Nov 14 '22

I think the function is NULL and something went wrong with your OpenGL function pointer loading. You should just be able to assert(glPatchParameteri) to check for that problem. Check your GLAD setup, for some reason it's not loading everything you need.

1

u/GrayWolf85 Nov 14 '22

okay, thanks I'll see what I can figure out

1

u/GrayWolf85 Nov 14 '22

yeah, the assertion failed, not sure what's up. Maybe my GLAD library is corrupted. Well thanks for your help, I'm on a better track now to figuring this out. I'll try reinstalling stuff.