Skip to content

Commit

Permalink
feat: on component destroy, release webgl memory
Browse files Browse the repository at this point in the history
  • Loading branch information
xnought committed Apr 6, 2024
1 parent ccecf39 commit 4da0edd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend/src/lib/Molstar.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<script lang="ts">
import { onDestroy } from "svelte";
import { PDBeMolstarPlugin } from "../../venome-molstar/lib";
import { loseWebGLContext } from "./venomeMolstarUtils";
export let url = "";
export let format = "pdb";
export let bgColor = { r: 255, g: 255, b: 255 }; // white
export let binary = false;
export let width = 500;
export let height = 500;
let m: PDBeMolstarPlugin;
let divEl: HTMLDivElement;
async function render() {
// @ts-ignore
const m = new PDBeMolstarPlugin(); // loaded through app.html
m = new PDBeMolstarPlugin();
// some bs for the whole thing to rerender. TODO: fix this.
divEl.innerHTML = "";
const div = document.createElement("div");
Expand All @@ -33,6 +35,11 @@
});
}
onDestroy(() => {
loseWebGLContext(divEl.querySelector("canvas")!);
m.plugin.dispose();
});
$: {
if (url && divEl) {
render();
Expand Down

0 comments on commit 4da0edd

Please sign in to comment.