Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cortex/webgl/resources/js/mriview.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ var mriview = (function(module) {
var surf = new surftype(this.active, opts);
surf.addEventListener("mix", this._mix);
surf.addEventListener("allowTilt", this._allowTilt);
// The SVG overlay (ROIs/sulci/labels) re-bakes its texture asynchronously, then
// dispatches "update" on the surface once the new texture is swapped in. Redraw when
// that lands, otherwise a toggle isn't visible until the next interaction.
surf.addEventListener("update", this.schedule.bind(this));
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.

medium

Using this.schedule.bind(this) directly in addEventListener creates a new function instance every time addSurf is called. This prevents the event listener from being properly removed later (e.g., in rmSurf), which can lead to memory leaks.

To fix this, cache the bound function on this._schedule so the same reference can be reused and cleaned up. Note that you should also add this.surfs[i].removeEventListener("update", this._schedule); to rmSurf to ensure proper cleanup.

Suggested change
surf.addEventListener("update", this.schedule.bind(this));
this._schedule = this._schedule || this.schedule.bind(this);
surf.addEventListener("update", this._schedule);


this.surfs.push(surf);
this.root.add(surf.object);
Expand Down