From 106ef9de49325ba137a672bfe169330b755608b5 Mon Sep 17 00:00:00 2001 From: triniwiz Date: Sun, 8 Nov 2026 20:17:56 -0400 Subject: [PATCH] fix(svg): create the Linux native view in createNativeView Svg created its GtkDrawingArea once, in the constructor, and returned it from createNativeView. Disposing the native view releases that widget, so when the same Svg was set up again (an Angular HMR update re-attaching the view tree) it handed back a freed widget: GTK logged invalid-widget criticals and the app crashed. Create the drawing area, and register its draw callback, each time the native view is created. --- packages/canvas-svg/index.linux.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/canvas-svg/index.linux.ts b/packages/canvas-svg/index.linux.ts index f9e59cdc..9bc4bb03 100644 --- a/packages/canvas-svg/index.linux.ts +++ b/packages/canvas-svg/index.linux.ts @@ -117,16 +117,13 @@ function svgData(source: string): SvgData | null { } export class Svg extends SVGBase { - private _area: any; + private _area: any = null; private _id = nextView++; private _raster: Raster | null = null; private _scale = 1; constructor() { super(); - this._area = gtk_drawing_area_new(); - views.set(this._id, new WeakRef(this)); - gtk_drawing_area_set_draw_func(this._area, sharedDrawFunc(), new interop.Pointer(this._id), null); this.on('layoutChanged', () => { // A percentage root size is relative to the view, so a new layout can change it. this.__rootSizeValid = false; @@ -135,7 +132,12 @@ export class Svg extends SVGBase { } createNativeView() { - return this._area; + // a new widget each time: disposing the native view frees the previous one + const area = gtk_drawing_area_new(); + views.set(this._id, new WeakRef(this)); + gtk_drawing_area_set_draw_func(area, sharedDrawFunc(), new interop.Pointer(this._id), null); + this._area = area; + return area; } get native() { @@ -227,6 +229,7 @@ export class Svg extends SVGBase { disposeNativeView() { views.delete(this._id); this._freeRaster(); + this._area = null; super.disposeNativeView(); }