From c2ab322bd2ffd8d5b0c07b393dcce3d9181fe7d3 Mon Sep 17 00:00:00 2001
From: dsehnal <david.sehnal@gmail.com>
Date: Fri, 24 Feb 2023 13:10:35 +0100
Subject: [PATCH] Stop animation loop on dispose

---
 CHANGELOG.md                 | 5 ++++-
 src/mol-canvas3d/canvas3d.ts | 1 +
 src/mol-plugin/context.ts    | 1 +
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b61a6f7ff..6d8c59630 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,10 @@ Note that since we don't clearly distinguish between a public and private interf
 
 ## [Unreleased]
 
-- allow link cylinder/line `dashCount` set to '0'
+## [v3.31.4] - 2023-02-24
+
+- Allow link cylinder/line `dashCount` set to '0'
+- Stop animation loop when disposing `PluginContext` (thanks @gfrn for identifying the issue)
 
 ## [v3.31.3] - 2023-02-22
 
diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts
index 9c93941a0..a993df511 100644
--- a/src/mol-canvas3d/canvas3d.ts
+++ b/src/mol-canvas3d/canvas3d.ts
@@ -908,6 +908,7 @@ namespace Canvas3D {
             },
             dispose: () => {
                 contextRestoredSub.unsubscribe();
+                cancelAnimationFrame(animationFrameHandle);
 
                 markBuffer = [];
 
diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts
index 92fd7bfaa..03346bbc3 100644
--- a/src/mol-plugin/context.ts
+++ b/src/mol-plugin/context.ts
@@ -362,6 +362,7 @@ export class PluginContext {
         }
         this.subs = [];
 
+        this.animationLoop.stop();
         this.commands.dispose();
         this.canvas3d?.dispose();
         this.canvas3dContext?.dispose(options);
-- 
GitLab