Comments (9)
mmmm... is a new bug or was happening before?
from glslviewer.
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:
- There's a race condition where the window changes size in between the two GLFW calls in getPixelDensity, causing framebuffer_width < window_width.
- You are performing an integer division instead of a floating point division, but you are returning a float.
from glslviewer.
nice catch!
from glslviewer.
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.
no when it change from retina screen to non-retina screens
from glslviewer.
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.
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.
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.
thanks for the heads up
from glslviewer.
Related Issues (20)
- glslViewer - Blender add-on: do not re-calucalate frame buffer size. (MacBook M1)
- Trying to write shader with lines from OBJ file HOT 4
- Release 3.2.1 filenames mismatch version number
- es 3.0 not working, extensions not working HOT 2
- Can virtual cameras be opened as streams in Windows?
- Screenshots are twice the resolution specified
- Crash when clearing loaded models
- Spaces cauing issues without syntax errors
- Missing Include and installation docs for Suse
- glslViewer does not compile. HOT 8
- Setting Icon= in desktop file not always working HOT 1
- glslViewer looks for libavdevice.so.58, but I have 59 (Debian 12.1) HOT 4
- 3.2.2 win64 Record video rate not being set correctly HOT 1
- A way to pipe the image output directly to STDOUT instead of saving to a file in headless mode?
- Installer
- [bug] Segmentation fault within the `ncurses` console because of a race condition HOT 1
- [BUG] macro expansion causes syntax error
- Launch with file that doesn't have .frag extension HOT 2
- Audio - NULL Capture Device on Mac HOT 1
- Raspberry PI 5 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glslviewer.