Repository navigation
Fix screenshot() raising when interact=True - #337
Merged
JWock82 merged 1 commit intoSep 13, 2026
Merged
Conversation
render_model() finalizes the render window right after the interactor closes, then screenshot() was taking that already-finalized window and handing it to vtkWindowToImageFilter, then finalizing it a second time. That's why the shear wall advanced example was throwing SetInput errors after the user closed the interactive window - it's grabbing a window that's already been torn down. Gave render_model() an internal _finalize flag so screenshot() can grab the pixels before the window gets finalized instead of after. Everything that calls render_model() directly still gets the old behavior since the flag defaults to True. Added a test that checks the finalize doesn't happen before the capture. Confirmed it fails on the old code and passes with the fix. Full suite still passes, 184 tests. Fixes JWock82#324
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The sequencing fix and regression test address the reported interactive screenshot failure.
Pull request overview
Fixes VTK screenshot failures when interact=True by deferring render-window finalization until after image capture.
Changes:
- Adds an internal
_finalizeoption torender_model(). - Updates
screenshot()to capture before finalizing. - Adds regression coverage for call order.
File summaries
| File | Description |
|---|---|
Testing/test_Visualization.py |
Adds regression coverage for interactive screenshots. |
Pynite/Visualization.py |
Corrects render-window finalization sequencing. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dug into this one since I hit something similar. The order of operations in
screenshot()is backwards wheninteract=True.render_model()finalizes the render window as soon as the interactor loop ends (right after the user closes the window).screenshot()callsrender_model()to get the window, but by the time it comes back it's already been finalized, sow2if.SetInput(window)gets a window that's already torn down. Thenscreenshot()finalizes it again on top of that.I couldn't get the exact TypeError to show up on my machine (macOS, VTK 9.7), it just silently goes through, which lines up with what was said in the issue about not being able to reproduce it on their end. But the sequencing is wrong regardless of platform, and it explains why it only shows up with
interact=True(theinteract=Falsepath never finalizes early, which is also why the existing screenshot tests never caught it, they all useinteract=False).Fix is small:
render_model()takes an internal_finalizeflag now,screenshot()passes False so it can grab the image before finalizing, then finalizes it itself right after. Nothing else changes, all the examples that callrender_model()on its own still finalize the same way they always did.Added a test that spies on the Finalize/SetInput calls to make sure capture happens first. Ran it against the old code with git stash and it fails exactly as expected, passes with the fix in place.
Ran the full test suite in a clean venv, 184 passed.
Fixes #324