Window crashed when resizing in diagonal

I have an applcation that uses a thread for rendering and the main thread is used to call glfwpollevents.

render thread:

            m_Render_thread = std::thread([this] {
                while(!shouldClose())
                {
                    glfwMakeContextCurrent(this->m_Win);
                    glClear(GL_COLOR_BUFFER_BIT);

                    glfwSwapBuffers(this->m_Win);
                }
            });

When I resize the screen from left to rigth, or top to bottom, everything is smooth and works perfectly, but when I resize it in diagonal, it immediatly crashes.

There is no event handling or nothing.
There is simply a mainthread with a single function : glfwpollevents()
And a render thread as shown above.

Hi @BleastT,

Welcome the GLFW forum.

Do you have the call stack of where the crash occurred?

Can you post the entirety of the application code here? If you can’t share all your code create a simple test app which demonstrates the crash.

I’m using vscode for this project and I can’t find a way to copy the whole call stack so I only have screenshots.


[Unknown/Just-In-Time compiled code] (Unknown Source:0)


Here is an example code where the crash occurs for me when you resize in diagonal

#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <thread>
#include <iostream>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);


    if(glewInit() != GLEW_OK)
    {
        std::cout << "Failed to init glew" << std::endl;
        return -1;
    }
    else{
        std::cout << glGetString(GL_VERSION) << std::endl;
    }


    glfwMakeContextCurrent(NULL);
    std::thread render_thread([window] {
        
        while(true)
        {
            glfwMakeContextCurrent(window);
            /* Render here */
            glClear(GL_COLOR_BUFFER_BIT);

            /* Swap front and back buffers */
            glfwSwapBuffers(window);
        }
    });

    /* Loop until the user closes the window */
    while (true)
    {
       glfwPollEvents();
    }

    render_thread.join();

    glfwTerminate();
    return 0;
}

Here is a screenshot of the disassembly view as well.

My system:
intel i7-10870h
rtx 3060 mobile
window x64

I slightly modified your code to make the most basic threaded app:

#include <GLFW/glfw3.h>
#include <thread>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);


    glfwMakeContextCurrent(NULL);
    std::thread render_thread([window] {
        
        glfwMakeContextCurrent(window);
        while(!glfwWindowShouldClose(window))
        {
            /* Render here */
            glClear(GL_COLOR_BUFFER_BIT);

            /* Swap front and back buffers */
            glfwSwapBuffers(window);
        }
    });

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
       glfwPollEvents();
    }
    render_thread.join();

    glfwTerminate();
    return 0;
}

Your code (without GLEW code as it’s not required here) and this code did not crash when resizing or moving in any way including diagonally.

I can’t see anything in the call stack image you show, the fact it shows Unknown Source makes me think this is from an injected DLL, similar to other issues I have seen with Nahimic:

The solution there was to uninstall Nahimic. Asus’s Sonic Suite has also caused issues, as have some viruses.

2 Likes

Oh wow! it actually worked. Thank you very much.

I disabled nahimic service and it doesnt crash anymore. The window resize is even smoother than before.
Does this mean that if I run this prorgam on a computer that has Nahimic the app would crash or do I just need to build my project while nahimic is disabled?

Sadly this is an issue in Nahimic, and so apps running on a computer that has Nahimic might crash.

A workaround is to detect Nahimic injection and warn the user:

1 Like

Thank you very much !