glfw program crashing in WSL2

  c++, glfw, wsl-2, xserver

I’m trying to run the example GLFW program on WSL2 with vcxsrv as the X server. There are no problems running the current program with the two lines commented out. When I uncomment only glCear(CL_COLOR_BUFFER_BIT);, it lags a bit when I drag the window around. When I uncomment only glfwSwapBuffers(window) the program crashes as soon as the window pops up, where dragging the window around becomes very laggy, and I am unable to close the window without terminating the app through the terminal. Why is this happening? Is there any way to improve the speed of these programs on WSL2?

Program:

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


static void glfwError(int /*id*/, const char* description)
{
    std::cerr << description << 'n';
}

int main(void)
{
    GLFWwindow* window;
    glfwSetErrorCallback(&glfwError);

    /* 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);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        // glClear(GL_COLOR_BUFFER_BIT);

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

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT