Skip to content

Commit a20279f

Browse files
Fixed potential memory leak + simplified nv.sync_opts
1 parent 76ef7a9 commit a20279f

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

js/widget.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
} from "./types.ts";
1818

1919
let nv: niivue.Niivue;
20-
let syncInterval: number;
20+
let syncInterval: number | undefined;
2121

2222
// Attach model event handlers
2323
function attachModelEventHandlers(
@@ -599,6 +599,11 @@ function attachCanvasEventHandlers(nv: niivue.Niivue, model: Model) {
599599
}
600600

601601
function setupSyncInterval(nv: niivue.Niivue, model: Model) {
602+
if (syncInterval !== undefined) {
603+
clearInterval(syncInterval);
604+
syncInterval = undefined;
605+
}
606+
602607
let lastSentScene: Scene | null = model.get("scene");
603608
let shouldSendScene = false;
604609
const sendSceneUpdate = async () => {

src/ipyniivue/widget.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -846,19 +846,6 @@ class NiiVue(BaseAnyWidget):
846846
other_nv = t.List(t.Instance(object, allow_none=False), default_value=[]).tag(
847847
sync=False
848848
)
849-
sync_opts = t.Dict(
850-
default_value={
851-
"3d": False,
852-
"2d": False,
853-
"zoom_pan": False,
854-
"cal_min": False,
855-
"cal_max": False,
856-
"clip_plane": False,
857-
"gamma": False,
858-
"slice_type": False,
859-
"crosshair": False,
860-
}
861-
).tag(sync=False)
862849

863850
@t.validate("other_nv")
864851
def _validate_other_nv(self, proposal):
@@ -876,28 +863,6 @@ def _validate_other_nv(self, proposal):
876863
)
877864
return value
878865

879-
@t.validate("sync_opts")
880-
def _validate_sync_opts(self, proposal):
881-
ALLOWED_KEYS = {
882-
"3d",
883-
"2d",
884-
"zoom_pan",
885-
"cal_min",
886-
"cal_max",
887-
"clip_plane",
888-
"gamma",
889-
"slice_type",
890-
"crosshair",
891-
}
892-
value = proposal["value"]
893-
invalid_keys = set(value.keys()) - ALLOWED_KEYS
894-
if invalid_keys:
895-
raise t.TraitError(
896-
f"Invalid keys in sync_opts: {invalid_keys}. "
897-
f"Allowed keys: {ALLOWED_KEYS}"
898-
)
899-
return value
900-
901866
def __init__(self, height: int = 300, **options): # noqa: D417
902867
r"""
903868
Initialize the NiiVue widget.
@@ -918,11 +883,22 @@ def __init__(self, height: int = 300, **options): # noqa: D417
918883
super().__init__(height=height, opts=opts, volumes=[], meshes=[])
919884

920885
# Initialize values
886+
self.this_model_id = self._model_id
921887
self._cluts = self._get_initial_colormaps()
922888
self.graph = Graph(parent=self)
923889
self.scene = Scene(parent=self)
924890
self.other_nv = []
925-
self.this_model_id = self._model_id
891+
self.sync_opts = {
892+
"3d": False,
893+
"2d": False,
894+
"zoom_pan": False,
895+
"cal_min": False,
896+
"cal_max": False,
897+
"clip_plane": False,
898+
"gamma": False,
899+
"slice_type": False,
900+
"crosshair": False,
901+
}
926902

927903
# Handle messages coming from frontend
928904
self._event_handlers = {}

0 commit comments

Comments
 (0)