ui/winui/image.cpp

changeset 108
77254bd6dccb
parent 76
641dcc79e0ef
--- a/ui/winui/image.cpp	Sat Apr 05 17:57:04 2025 +0200
+++ b/ui/winui/image.cpp	Sun Jul 20 22:04:39 2025 +0200
@@ -47,6 +47,16 @@
 
 UiImageSource::UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src) : imgsrc(src) {}
 
+void UiImageSource::ref() {
+	refcount++;
+}
+
+void UiImageSource::unref() {
+	if (--refcount == 0) {
+		delete this;
+	}
+}
+
 UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) {
     UiObject* current = uic_current_obj(obj);
     
@@ -94,9 +104,10 @@
     UiImageSource *imgdata = (UiImageSource*)data;
     if (g->value) {
         UiImageSource *prevData = (UiImageSource*)g->value;
-        delete prevData;
+        //prevData->unref();
     }
     g->value = imgdata;
+    //imgdata->ref();
 
     UiWidget* widget = (UiWidget*)g->obj;
     Image image = widget->uielement.as<Image>();
@@ -117,8 +128,19 @@
 
     UiImageSource *imgdata = new UiImageSource(src);
     obj->set(obj, imgdata, UI_IMAGE_OBJECT_TYPE);
+    imgdata->unref();
 
     free(wpath);
 
     return 0;
 }
+
+void ui_image_ref(UIIMAGE img) {
+    UiImageSource* imgdata = (UiImageSource*)img;
+    imgdata->ref();
+}
+
+void ui_image_unref(UIIMAGE img) {
+    UiImageSource* imgdata = (UiImageSource*)img;
+    imgdata->unref();
+}

mercurial