Skip to content

fix: Add GL context lock for server mode - #221

Merged
LKasianAnsys merged 3 commits into
mainfrom
fix/add-gl-context-lock-for-server-mode
Nov 17, 2026
Merged

LKasianAnsys merged 3 commits into
mainfrom
fix/add-gl-context-lock-for-server-mode

Conversation

@LKasianAnsys

Copy link
Copy Markdown
Collaborator

Issue

Resolves #220

Description

In SERVER mode, remove_dataset was causing a black canvas in the viewer, or a server crash. This is because removing an actor makes VTK make the GL context current on the calling thread (the REST thread) and leave it there. A GL context can only be current on one thread at a time, so the Trame thread could no longer make it current to render the next frame. This isn't limited to remove_dataset; e.g. turning the cross-section off (as load_state can) does the same thing.

Rather than adding inline ReleaseCurrent() calls at each call site, this PR adds a GlContextLock, used as the scene lock in SERVER mode only. When the outermost hold of the lock ends, it calls ReleaseCurrent() if the context is current on that thread, so any GL work done under the scene lock leaves the context free for the next thread. This replaces the ReleaseCurrent() call in VisorRcaWindow and removes the need for one in ServerRenderer.deregister_node (which would have been the other option here for the remove_dataset fix.

Known limitation: This only covers GL work done while holding the scene lock, which every VTK operation touches today.

@github-actions github-actions Bot added test Work associated with testing fixed bug Something isn't working labels Nov 13, 2026
@LKasianAnsys LKasianAnsys self-assigned this Nov 13, 2026
@LKasianAnsys
LKasianAnsys force-pushed the fix/add-gl-context-lock-for-server-mode branch from a9576b7 to 4972654 Compare November 16, 2026 19:04
@LKasianAnsys
LKasianAnsys added this pull request to stack #224 November 16, 2026 19:30

@ansBAkula ansBAkula left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested and works.

@LKasianAnsys
LKasianAnsys merged commit 2f9b0c8 into main Nov 17, 2026
21 of 22 checks passed
@LKasianAnsys
LKasianAnsys deleted the fix/add-gl-context-lock-for-server-mode branch November 17, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixed test Work associated with testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug located in remove_dataset in SERVER mode

3 participants