8000 Fix screenshot() raising when interact=True by Ayberkrk · Pull Request #337 · JWock82/Pynite · GitHub
[go: up one dir, main page]

Skip to content

Fix screenshot() raising when interact=True - #337

Merged
JWock82 merged 1 commit into
JWock82:mainfrom
Ayberkrk:fix-screenshot-interact-finalize-order
Sep 13, 2026
Merged

JWock82 merged 1 commit into
JWock82:mainfrom
Ayberkrk:fix-screenshot-interact-finalize-order

Conversation

@Ayberkrk
Copy link
Copy Markdown
Contributor

Dug into this one since I hit something similar. The order of operations in screenshot() is backwards when interact=True.

render_model() finalizes the render window as soon as the interactor loop ends (right after the user closes the window). screenshot() calls render_model() to get the window, but by the time it comes back it's already been finalized, so w2if.SetInput(window) gets a window that's already torn down. Then screenshot() 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 (the interact=False path never finalizes early, which is also why the existing screenshot tests never caught it, they all use interact=False).

Fix is small: render_model() takes an internal _finalize flag 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 call render_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

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
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 _finalize option to render_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.

@JWock82
JWock82 merged commit 0a65eef into JWock82:main Sep 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering Shear Wall - Advanced Example Fails

3 participants

0