-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix glutReshapeFunc not being called (closes #7133) #9835
Fix glutReshapeFunc not being called (closes #7133) #9835
Conversation
Thank you for submitting a pull request! If this is your first PR, make sure to add yourself to AUTHORS. |
Thanks @haberbyte ! Would be good to improve this code. At first glance this looks good, but I'll need to read this more carefully. First thing, though, can you see the test failures on CI here locally? Let me know if you need help debugging those. |
Ah yes I see the failures and will try to fix them over the weekend, thanks! Will ping you once i think this is in a good state. |
@kripken Ok CI is now passing. I removed the deprecated requestFullScreen and cancelFullScreen stuff as well. Not sure if that is ok to do, but i figured it would be since it is marked deprecated for years now. Let me know if you would rather have that in a separate PR. |
@haberbyte I think that should be in a separate PR, yes. While it's been deprecated for a while, some users will break by that change. We should at least have it in a separate commit so bisection is more clear. But thanks for doing it, it's a good idea! |
Not sure why I had to retrigger the build for it to pass, but the failure was unrelated to the changes here. I removed the deprecated functions in a separate PR here: #9861 |
src/library_glut.js
Outdated
@@ -361,15 +367,11 @@ var LibraryGLUT = { | |||
window.addEventListener("mousedown", GLUT.onMouseButtonDown, true); | |||
window.addEventListener("mouseup", GLUT.onMouseButtonUp, true); | |||
// IE9, Chrome, Safari, Opera | |||
window.addEventListener("mousewheel", GLUT.onMouseWheel, true); | |||
window.addEventListener("mousewheel", GLUT.onMouseWheel, { passive: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this changes the capture property, doesn't it? shouldn't we add capture: true
to be backwards compatible? or is this part of the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The "passive: false" change is not part of the fix. This is just to silence Chrome's warning about passive event listeners trying to preventDefault.
src/library_glut.js
Outdated
window.addEventListener("DOMMouseScroll", GLUT.onMouseWheel, true); | ||
window.addEventListener("DOMMouseScroll", GLUT.onMouseWheel, { capture: true, passive: false }); | ||
|
||
window.addEventListener("resize", GLUT.onResize, true); | ||
|
||
Browser.resizeListeners.push(function(width, height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need both a resizeListener and a listener on the window itself? I'm not sure why the resizeListener isn't enough by itself. (If I'm missing something here, maybe adding a comment here would help other people reading the code in the future?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug i was hitting is that the reshape function would not be called.
I have a canvas element styled with CSS to 100% width/height, so a simple resizing of the window would update the size of the canvas element.
I am not too familiar with what the library_browser.js does out of the box, but it seems like it does not handle those resizes of the canvas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks.
Reading the existing code some more, it looks like none of the other input systems (sdl, etc.) listens for window resize events. And so this looks like a general issue, that maybe the resizeListeners should be called for.
And IIUC the CSS you describe, then your canvas spans the whole window, so I think a resize event should be fired on the canvas, if the window is resized. So listening on the canvas should be enough - but it looks like we don't do that either - we just look for fullscreen resizing.
In summary how about if in library_browser.js, in the init
function, we add an event listener for the resize event, at the very end to the canvas, that calls Browser.updateResizeListeners
(alongside the other events listened to in the block with if (canvas) {
. Would that fix your use case? If so I think it might be a more general fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would fix my case.
I will implement the more general fix then (within this PR I guess, so we can keep the discussion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Yes, in this same PR is simplest and best, I think.
The deletion of the Re-opening and re-targeting to master. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
Any chance this could be re-based and landed still? |
Sorry for the force pushes, had some trouble getting this rebased right. But i think now it is correct. |
Thanks @haberbyte ! I think this fix is correct. But it's a little odd to me that we didn't have more bug reports on this, as the fix here is quite general - more than glut, it's basically a fix for all the UI APIs. That makes me wonder if I'm not missing something here - ? It would be good to add a test for this. It could be like |
I'm the author of the original issue (#7133 - sorry for disappearing!) and I'm also curious, why a general UI fix is needed here and the fix is not limited to GLUT. Maybe #7133 and #9835 are in fact different problems? In regards to #7133, I never encountered any window resizing issues with SDL+OGLES code. For example, https://erik-larsen.github.io/emscripten-sdl2-ogles2/hello_triangle.html works fine with window resizing by watching for SDL_WINDOWEVENT_SIZE_CHANGED and then updating the GL side with a glViewport call:
GLUT on the other hand, never receives any window resize event (not on window init, nor subsequent resizes). Part of the problem here may be that the html generated by
I did try the fix proposed by @haberbyte, but this still doesn't seem to fix my case of tests/hello_world_gles.c with the above resizable-canvas html. By the way, this is precisely the same HTML I'm using for SDL+OGLES code, which as mentioned above, works fine in getting resize events. I know @haberbyte you mentioned you weren't working with GLUT any more. I'd be glad to keep looking at this, at least for the case of getting window resize events into GLUT. |
Oof, please disregard my last wall of text. After more code research and re-reading this thread, I do believe @haberbyte has the right fix. It is consistent with this GLUT change from 2013. I just need to figure out why it is not working for my case. |
I figured out why my case is still not working. The fix here ( So, it seems an additional fix is needed here, that updates the canvas width and height on window resizing. |
So the following solves the problem completely for me (canvas = 100% window case), although I am not sure about other cases: library_glut.js:
library_browser.js:
|
This fixes the issue in #7133 for me and the reshape function callback is called on resize.
I also added { passive: false } to the mouse event listeners as Chrome is complaining about it.
I also noticed some quite old "requestFullScreen" deprecations, should i remove those methods as well? I would like to cleanup the glut library code a bit.