Giter Club home page Giter Club logo

Comments (9)

patriciogonzalezvivo avatar patriciogonzalezvivo commented on May 13, 2024

mmmm... is a new bug or was happening before?

from glslviewer.

doug-moen avatar doug-moen commented on May 13, 2024

this looks suspicious:

#8: onViewportResize (_newWidth=0, _newHeight=0)
(gdb) frame 9
#9  0x0000000000431e85 in setWindowSize (_width=<optimized out>, 
    _height=<optimized out>) at src/app.cpp:419
419	    onViewportResize(viewport.z, viewport.w);
(gdb) print viewport
$1 = {{x = 0, r = 0, s = 0}, {y = 0, g = 0, t = 0}, {z = 0, b = 0, p = 0}, {
    w = 0, a = 0, q = 0}}
(gdb) frame 10
#10 0x0000000000432094 in <lambda(GLFWwindow*, int, int)>::operator() (
    __closure=0x0, _window=<optimized out>, _h=500, _w=607) at src/app.cpp:211
211	            setWindowSize(_w*devicePixelRatio,_h*devicePixelRatio);
(gdb) print devicePixelRatio
$2 = 0

So why is devicePixelRatio == 0? Something is wrong with getPixelDensity(). I added a print statement:

float getPixelDensity() {
    #ifdef PLATFORM_RPI
        // RASPBERRYPI
        return 1.;
    #else
        // OSX/LINUX
        int window_width, window_height, framebuffer_width, framebuffer_height;
        glfwGetWindowSize(window, &window_width, &window_height);
        glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
        std::cout << "getPixelDensity: "<<framebuffer_width<<"/"<<window_width<<"="<<(framebuffer_width/window_width)<<"\n";
        return framebuffer_width/window_width;
    #endif
}
getPixelDensity: 500/500=1
getPixelDensity: 510/510=1
getPixelDensity: 515/515=1
getPixelDensity: 515/515=1
getPixelDensity: 517/517=1
getPixelDensity: 517/517=1
getPixelDensity: 517/517=1
getPixelDensity: 521/521=1
getPixelDensity: 521/521=1
getPixelDensity: 525/525=1
getPixelDensity: 525/525=1
getPixelDensity: 531/531=1
getPixelDensity: 541/541=1
getPixelDensity: 554/554=1
getPixelDensity: 567/567=1
getPixelDensity: 602/602=1
getPixelDensity: 636/636=1
getPixelDensity: 645/645=1
getPixelDensity: 646/646=1
getPixelDensity: 643/643=1
getPixelDensity: 641/641=1
getPixelDensity: 638/638=1
getPixelDensity: 638/638=1
getPixelDensity: 635/635=1
getPixelDensity: 631/631=1
getPixelDensity: 628/628=1
getPixelDensity: 626/626=1
getPixelDensity: 626/626=1
getPixelDensity: 622/622=1
getPixelDensity: 609/609=1
getPixelDensity: 605/605=1
getPixelDensity: 601/601=1
getPixelDensity: 596/596=1
getPixelDensity: 591/591=1
getPixelDensity: 590/590=1
getPixelDensity: 589/589=1
getPixelDensity: 592/592=1
getPixelDensity: 593/593=1
getPixelDensity: 595/595=1
getPixelDensity: 597/597=1
getPixelDensity: 599/599=1
getPixelDensity: 603/603=1
getPixelDensity: 609/609=1
getPixelDensity: 614/614=1
getPixelDensity: 615/615=1
getPixelDensity: 617/617=1
getPixelDensity: 618/618=1
getPixelDensity: 622/622=1
getPixelDensity: 628/628=1
getPixelDensity: 633/633=1
getPixelDensity: 637/637=1
getPixelDensity: 638/638=1
getPixelDensity: 641/641=1
getPixelDensity: 645/645=1
getPixelDensity: 648/648=1
getPixelDensity: 653/653=1
getPixelDensity: 657/657=1
getPixelDensity: 658/658=1
getPixelDensity: 661/661=1
getPixelDensity: 670/670=1
getPixelDensity: 670/670=1
getPixelDensity: 672/672=1
getPixelDensity: 676/676=1
getPixelDensity: 677/677=1
getPixelDensity: 705/705=1
getPixelDensity: 705/705=1
getPixelDensity: 706/706=1
getPixelDensity: 708/708=1
getPixelDensity: 709/709=1
getPixelDensity: 710/710=1
getPixelDensity: 711/711=1
getPixelDensity: 714/714=1
getPixelDensity: 715/715=1
getPixelDensity: 716/716=1
getPixelDensity: 712/712=1
getPixelDensity: 709/709=1
getPixelDensity: 709/709=1
getPixelDensity: 709/709=1
getPixelDensity: 707/707=1
getPixelDensity: 699/704=0
glslViewer: include/glm/gtx/../gtc/matrix_transform.inl:236: glm::tmat4x4<T, (glm::precision)0u> glm::perspectiveRH(T, T, T, T) [with T = double]: Assertion `abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)' failed.
Aborted (core dumped)

Diagnosis:

  1. There's a race condition where the window changes size in between the two GLFW calls in getPixelDensity, causing framebuffer_width < window_width.
  2. You are performing an integer division instead of a floating point division, but you are returning a float.

from glslviewer.

patriciogonzalezvivo avatar patriciogonzalezvivo commented on May 13, 2024

nice catch!

from glslviewer.

doug-moen avatar doug-moen commented on May 13, 2024

I have a proposed fix, but I don't know these APIs, so you tell me...

In the following code,

        window = glfwCreateWindow(_viewport.z, _viewport.w, appTitle.c_str(), NULL, NULL);

        if(!window) {
            glfwTerminate();
            std::cerr << "ABORT: GLFW create window failed" << std::endl;
            exit(-1);
        }

        devicePixelRatio = getPixelDensity();
        setWindowSize(_viewport.z*devicePixelRatio, _viewport.w*devicePixelRatio);

        glfwMakeContextCurrent(window);
        glfwSetWindowSizeCallback(window, [](GLFWwindow* _window, int _w, int _h) {
            devicePixelRatio = getPixelDensity();
            setWindowSize(_w*devicePixelRatio,_h*devicePixelRatio);
        });

why do you recompute devicePixelRatio inside of the WindowSizeCallback function? (Because that seems to be the cause of the bug.) Isn't the pixel density constant for the lifetime of the window?

from glslviewer.

patriciogonzalezvivo avatar patriciogonzalezvivo commented on May 13, 2024

no when it change from retina screen to non-retina screens

from glslviewer.

doug-moen avatar doug-moen commented on May 13, 2024

So that would be a multi-monitor setup with both a retina and a non-retina monitor.

If you are resizing the window, you are dragging one of the window boundaries. The body of the window remains on the original monitor, and the pixel density shouldn't change. It is only when you drag the window from one monitor to another (which does not resize it, I think) that the pixel density could change.

So maybe you should update the devicePixelRatio when the window is moved, and not when it is resized. You could use glfwSetWindowPosCallback for that.

Again, I am not familiar with these APIs. Does this make sense?

from glslviewer.

patriciogonzalezvivo avatar patriciogonzalezvivo commented on May 13, 2024

You are right! It doesn't trigger the resize when pass between screens with different pixel density.
using glfwSetWindowPosCallback makes a lot of sense.

Wanna do a PR?

Thanks again!

from glslviewer.

doug-moen avatar doug-moen commented on May 13, 2024

The crash is now fixed. Two remaining issues from the discussion above:

  • In getPixelDensity(), we are performing an integer division instead of a floating point division, but returning a float. The devicePixelRatio might not be an integer! "Android phones often have DPRs of 1.5" according to https://www.html5rocks.com/en/mobile/high-dpi/. And this page discusses non-integer pixel scaling ratios on Linux: https://bugzilla.mozilla.org/show_bug.cgi?id=1214470.
  • When a window is dragged to another monitor with a different pixel density, we should recompute the cached pixel density. This could be done using glfwSetWindowPosCallback.

from glslviewer.

patriciogonzalezvivo avatar patriciogonzalezvivo commented on May 13, 2024

thanks for the heads up

from glslviewer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.