Exception thrown when shaders are created #4428

Closed
opened 2021-08-12 03:39:32 +00:00 by Lester702 · 7 comments
Lester702 commented 2021-08-12 03:39:32 +00:00 (Migrated from github.com)

version: 1.83
branch: master
imgui_impl_opengl3
imgui_impl_sdl

I just finished getting everything working and compiled and ran my program, but as soon as it starts it stops and I get

Exception thrown at 0x0000000000000000 in Henly.exe: 0xC0000005: Access violation executing location 0x0000000000000000.

The exception is in imgui_impl_opengl3.cpp and is at this chunk of code

// Create shaders
    const GLchar* vertex_shader_with_version[2] = { g_GlslVersionString, vertex_shader };
    g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(g_VertHandle, 2, vertex_shader_with_version, NULL);
    glCompileShader(g_VertHandle);
    CheckShader(g_VertHandle, "vertex shader");

    const GLchar* fragment_shader_with_version[2] = { g_GlslVersionString, fragment_shader };
    g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(g_FragHandle, 2, fragment_shader_with_version, NULL);
    glCompileShader(g_FragHandle);
    CheckShader(g_FragHandle, "fragment shader");

    g_ShaderHandle = glCreateProgram();
    glAttachShader(g_ShaderHandle, g_VertHandle);
    glAttachShader(g_ShaderHandle, g_FragHandle);
    glLinkProgram(g_ShaderHandle);
    CheckProgram(g_ShaderHandle, "shader program");

    g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
    g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
    g_AttribLocationVtxPos = (GLuint)glGetAttribLocation(g_ShaderHandle, "Position");
    g_AttribLocationVtxUV = (GLuint)glGetAttribLocation(g_ShaderHandle, "UV");
    g_AttribLocationVtxColor = (GLuint)glGetAttribLocation(g_ShaderHandle, "Color");

Here is the repo if you want to clone it and run it

https://github.com/Lester702/Henly/tree/testing_imgui

version: 1.83 branch: master imgui_impl_opengl3 imgui_impl_sdl I just finished getting everything working and compiled and ran my program, but as soon as it starts it stops and I get ``` Exception thrown at 0x0000000000000000 in Henly.exe: 0xC0000005: Access violation executing location 0x0000000000000000. ``` The exception is in imgui_impl_opengl3.cpp and is at this chunk of code ``` // Create shaders const GLchar* vertex_shader_with_version[2] = { g_GlslVersionString, vertex_shader }; g_VertHandle = glCreateShader(GL_VERTEX_SHADER); glShaderSource(g_VertHandle, 2, vertex_shader_with_version, NULL); glCompileShader(g_VertHandle); CheckShader(g_VertHandle, "vertex shader"); const GLchar* fragment_shader_with_version[2] = { g_GlslVersionString, fragment_shader }; g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(g_FragHandle, 2, fragment_shader_with_version, NULL); glCompileShader(g_FragHandle); CheckShader(g_FragHandle, "fragment shader"); g_ShaderHandle = glCreateProgram(); glAttachShader(g_ShaderHandle, g_VertHandle); glAttachShader(g_ShaderHandle, g_FragHandle); glLinkProgram(g_ShaderHandle); CheckProgram(g_ShaderHandle, "shader program"); g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture"); g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx"); g_AttribLocationVtxPos = (GLuint)glGetAttribLocation(g_ShaderHandle, "Position"); g_AttribLocationVtxUV = (GLuint)glGetAttribLocation(g_ShaderHandle, "UV"); g_AttribLocationVtxColor = (GLuint)glGetAttribLocation(g_ShaderHandle, "Color"); ``` Here is the repo if you want to clone it and run it https://github.com/Lester702/Henly/tree/testing_imgui
ocornut commented 2021-08-12 06:51:49 +00:00 (Migrated from github.com)

Closing as lacking sufficient information and generally not our problem, given the scope of the codebase.

Use a debugger to isolate the exact source code and function call leading to a crash.
Make sure you passed a valid glsl version to ImGuiImplOpenGL3_Init().
Make sure the backend has the GL loader it uses correctly initialized by your application.

Closing as lacking sufficient information and generally not our problem, given the scope of the codebase. Use a debugger to isolate the exact source code and function call leading to a crash. Make sure you passed a valid glsl version to ImGuiImplOpenGL3_Init(). Make sure the backend has the GL loader it uses correctly initialized by your application.
Lester702 commented 2021-08-12 14:23:45 +00:00 (Migrated from github.com)

All the issues literally come from ImGui

All the issues literally come from ImGui
thedmd commented 2021-08-12 14:30:51 +00:00 (Migrated from github.com)

Omar suggested what you can do to find why your project is crashing.
Please investigate it before you jump to conclusions.

Omar suggested what you can do to find why your project is crashing. Please investigate it before you jump to conclusions.
Lester702 commented 2021-08-12 15:26:41 +00:00 (Migrated from github.com)

Omar suggested what you can do to find why your project is crashing.
Please investigate it before you jump to conclusions.

I was using the gl3w files that were in the ImGui/examples/libs folder and then switched to https://sourceforge.net/projects/glew/files/glew/2.1.0/
Which fixed my original problem, but now ImGui doesn't render to the window

> Omar suggested what you can do to find why your project is crashing. > Please investigate it before you jump to conclusions. I was using the gl3w files that were in the ImGui/examples/libs folder and then switched to https://sourceforge.net/projects/glew/files/glew/2.1.0/ Which fixed my original problem, but now ImGui doesn't render to the window
thedmd commented 2021-08-12 20:18:03 +00:00 (Migrated from github.com)

You can try to compare example_sdl_opengl3/main.cpp with your code and look for the differences. Maybe even debugging side by side to pin out the bug.

You can try to compare [example_sdl_opengl3/main.cpp](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/main.cpp) with your code and look for the differences. Maybe even debugging side by side to pin out the bug.
PathogenDavid commented 2021-08-12 20:28:13 +00:00 (Migrated from github.com)

All the issues literally come from ImGui

An error which occurs while Dear ImGui code is executing does not necessarily indicate an error caused by Dear ImGui.

By your own admission you're still learning C++. C++ is not like Python where inputs are constantly validated and friendly exceptions are thrown when you do something wrong. If you feed garbage into Dear ImGui (or any C++ library), you will get garbage out. (Sometimes you'll get an assert too, but there's only so much validation that can be done, especially in a memory-unsafe language.)

Which fixed my original problem, but now ImGui doesn't render to the window

We can't debug your entire app for you, there's a number of reasons this might be happening. @thedmd's suggestion is a good one.

Another thing in particular that stands out to me is this issue is for OpenGL but your repo appears to be using Vulkan but you seem to be using a custom SDL_render-based backend for Dear ImGui? You can't (easily) mix graphics APIs like this, you need to pick one and stick to it. (Also as an aside, I really would not recommend trying to learn Vulkan while you're still learning C++.)

> All the issues literally come from ImGui An error which occurs while Dear ImGui code is executing does not necessarily indicate an error caused by Dear ImGui. By your own admission you're still learning C++. C++ is not like Python where inputs are constantly validated and friendly exceptions are thrown when you do something wrong. If you feed garbage into Dear ImGui (or any C++ library), you will get garbage out. (Sometimes you'll get an assert too, but there's only so much validation that can be done, especially in a memory-unsafe language.) > Which fixed my original problem, but now ImGui doesn't render to the window We can't debug your entire app for you, there's a number of reasons this might be happening. @thedmd's suggestion is a good one. Another thing in particular that stands out to me is this issue is for OpenGL but your repo appears to be using Vulkan but you seem to be using a custom SDL_render-based backend for Dear ImGui? You can't (easily) mix graphics APIs like this, you need to pick one and stick to it. (Also as an aside, I really would not recommend trying to learn Vulkan while you're still learning C++.)
Lester702 commented 2021-08-12 20:49:40 +00:00 (Migrated from github.com)

Another thing in particular that stands out to me is this issue is for OpenGL but your repo appears to be using Vulkan but you seem to be using a custom SDL_render-based backend for Dear ImGui? You can't (easily) mix graphics APIs like this, you need to pick one and stick to it. (Also as an aside, I really would not recommend trying to learn Vulkan while you're still learning C++.)

I had just switched it to Vulkan, but realized that Vulkan requires more code than OpenGL to do something such as drawing a triangle

> Another thing in particular that stands out to me is this issue is for OpenGL but your repo appears to be using Vulkan but you seem to be using a custom SDL_render-based backend for Dear ImGui? You can't (easily) mix graphics APIs like this, you need to pick one and stick to it. (Also as an aside, I really would not recommend trying to learn Vulkan while you're still learning C++.) I had just switched it to Vulkan, but realized that Vulkan requires more code than OpenGL to do something such as drawing a triangle
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#4428
No description provided.