fix: Fix QMainWindow Resize Crash in Qt6#1082
fix: Fix QMainWindow Resize Crash in Qt6#1082williamwira wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
Conversation
92e6fa4 to
985415c
Compare
AcademySoftwareFoundation#1063) Signed-off-by: Will Wira <4399853+williamwira@users.noreply.github.com>
985415c to
6c65154
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a Qt6 crash regression when resizing the main window after the initial “fit to first media” resize by deferring a follow-up resize until after the first paintGL() completes.
Changes:
- Treat the first “resize to fit” as a special case (
firstTime=true) during the first non-empty render. - Schedule a second
resizeToFit()viaQTimer::singleShot(0, ...)to restore expected resizability after painting. - Adjust when
m_resetPolicyTimeris started duringresizeToFit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/app/RvCommon/RvDocument.cpp | Starts m_resetPolicyTimer only within the resize path and documents first-time behavior. |
| src/lib/app/RvCommon/GLView.cpp | Introduces a queued “second resize” after first paint to avoid the Qt6 crash state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // OpenRV Issue #1063 | ||
| // | ||
| // When upgrading Qt6, calling resizeToFit the first time | ||
| // previously resulted in a crashable state when | ||
| // QMainWindow::resize was called. | ||
| // | ||
| // Now we skip calling that on the first time (above). | ||
| // In resizeToFit, the function also doesn't execute | ||
| // "m_resetPolicyTimer->start()" the first time, as that | ||
| // interferes with the "Fit Window to First Media Loaded" | ||
| // option. |
There was a problem hiding this comment.
The comment is ambiguous in “skip calling that” (it reads as if resizeToFit() is skipped, but the code still calls it with firstTime=true). Consider rewording to explicitly say what is skipped on firstTime (e.g., “resizeToFit(firstTime=true) avoids calling QMainWindow::resize / avoids starting m_resetPolicyTimer on the first invocation”) to make the rationale unambiguous for future maintainers.
| QTimer::singleShot(0, this, | ||
| [this]() | ||
| { | ||
| m_doc->resizeToFit(false, false); | ||
| m_doc->center(); |
There was a problem hiding this comment.
This queued lambda dereferences m_doc later, but it only captures this, so it will use whatever m_doc happens to be at callback time (and could be invalid/replaced if the document changes between scheduling and execution). Capture a stable reference at scheduling time (e.g., a QPointer if it’s a QObject, or an owning/weak handle used in this codebase) and use that inside the lambda to ensure the callback targets the intended, still-alive document.
| QTimer::singleShot(0, this, | |
| [this]() | |
| { | |
| m_doc->resizeToFit(false, false); | |
| m_doc->center(); | |
| auto* const doc = m_doc; | |
| QTimer::singleShot(0, this, | |
| [doc]() | |
| { | |
| if (!doc) return; | |
| doc->resizeToFit(false, false); | |
| doc->center(); |
Linked issues
Fixes #1063
Summarize your change.
On the GLView's first paintGL routine, the Rv Window's resizeToFit function is now called from inside a singleShot. This causes it to run after the first paintGL completes, which avoids the state that previously caused the crash.
Describe the reason for the change.
OpenRV, when built with the VFX2024 option which includes Qt6 6.5.3, had a crash regression. The crash would occur when resizing the main window after the preference "Fit Window to First Media Loaded" executed.
Describe what you have tested and on which operating system.
Tested on Linux RHEL 9.6. Made sure the steps below no longer resulted in a crash:
-DRV_VFX_CY2024=1RV > Preferences > Fit Window to First Media Loadedis activerv colorchart,start=1,end=2,width=1920,height=804,fps=24.movieprocView > Lock Pixel Scale During Resize.