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

Exception thrown when shaders are created #4428

Closed
Lester702 opened this issue Aug 12, 2021 · 7 comments
Closed

Exception thrown when shaders are created #4428

Lester702 opened this issue Aug 12, 2021 · 7 comments

Comments

@Lester702
Copy link

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

@Lester702 Lester702 changed the title Exception thrown at 0x0000000000000000 in Henly.exe: 0xC0000005: Access violation executing location 0x0000000000000000. Exception thrown when shaders are created Aug 12, 2021
@ocornut
Copy link
Owner

ocornut commented Aug 12, 2021

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
Copy link
Author

All the issues literally come from ImGui

@thedmd
Copy link
Contributor

thedmd commented Aug 12, 2021

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

@Lester702
Copy link
Author

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
Copy link
Contributor

thedmd commented Aug 12, 2021

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.

@PathogenDavid
Copy link
Contributor

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
Copy link
Author

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants