Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

GLFW window width goes to 1 when resizing window horizontally #2783

@gomers-pile

Description

@gomers-pile

On Ubuntu 24.04.3 LTS and X11:

When resizing the window with either the left or right edge of the window, the window width will jump to 1 for a small range of widths. This only happens when glfwSetWindowAspectRatio() is used with actual values (not GLFW_DONT_CARE). It does not happen when dragging the corners or top/bottom edge to resize the window. The actual values for aspect ratio or initial window size doesn't seem to matter, but it affects the width at which the window collapses to 1. This issue occurred on versions 3.3.10 and "3.5.0" that I had on my machine.

Demo code:

#include <iostream>
#include "glfw3.h"

constexpr int DEFAULT_WINDOW_WIDTH = 1280;
constexpr int DEFAULT_WINDOW_HEIGHT = 720;

GLFWwindow* g_pWindow = nullptr;


void Framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    std::cout << width << ", " << height << "\n";
}


void SetupWindow()
{
    std::string windowName = "Test";
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    g_pWindow = glfwCreateWindow(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT, windowName.c_str(), NULL, NULL);
    if (g_pWindow == nullptr)
    {
        std::cout << "Failed to create GLFW window\n";
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    //glfwSetWindowSizeLimits(g_pWindow, GLFW_DONT_CARE, GLFW_DONT_CARE, GLFW_DONT_CARE, GLFW_DONT_CARE);
    glfwSetWindowAspectRatio(g_pWindow, 16, 9);

    glfwMakeContextCurrent(g_pWindow);

    glfwSetFramebufferSizeCallback(g_pWindow, Framebuffer_size_callback);
}


int main(int, char**)
{ 
    SetupWindow();

    while (!glfwWindowShouldClose(g_pWindow))
    {
        glfwPollEvents();
    }
}

Sample output in the terminal window while resizing the window:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    X11bugBug reports and bugfix pull requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions