openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

ofAppGLFWWindow - Incorrect value for pixelScreenCoordScale when minimizing window

Open pjulien21 opened this issue 3 years ago • 2 comments

When ofAppGLFWWindow is minimized, a call to ofAppGLFWWindow::resize_cb() is made while window and framebuffer width/height are 0.

Therefore, the code updates pixelScreenCoordScale with an invalid value (division by 0) :

void ofAppGLFWWindow::resize_cb(GLFWwindow* windowP_, int w, int h) {
	ofAppGLFWWindow * instance = setCurrent(windowP_);

	// Detect if the window is running in a retina mode

	int framebufferW, framebufferH; // <- physical pixel extents
	glfwGetFramebufferSize(windowP_, &framebufferW, &framebufferH);

	int windowW, windowH; // <- screen coordinates, which may be scaled
	glfwGetWindowSize(windowP_, &windowW, &windowH);

	// Find scale factor needed to transform from screen coordinates
	// to physical pixel coordinates
	instance->pixelScreenCoordScale = (float)framebufferW / (float)windowW;  // <----- Division by zero

Calls to ofGetWidth() and ofGetHeight() in ofApp::Draw()/ofApp::Update() then returns invalid values since they scale according to pixelScreenCoordScale .

pjulien21 avatar Mar 19 '22 02:03 pjulien21

any specific platform? all platforms? thanks

dimitre avatar Mar 26 '22 22:03 dimitre

I had the problem on Windows 10.

pjulien21 avatar Mar 27 '22 01:03 pjulien21