From c304f5f3159e61aec1bafa974fa0ad51d8715478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Leplat?= Date: Wed, 25 Feb 2026 10:33:58 +0000 Subject: [PATCH 1/3] Prevent temporary mat from being destroyed --- src/main/java/qupath/ext/djl/DjlTools.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/qupath/ext/djl/DjlTools.java b/src/main/java/qupath/ext/djl/DjlTools.java index 9998c5f..8e8e524 100644 --- a/src/main/java/qupath/ext/djl/DjlTools.java +++ b/src/main/java/qupath/ext/djl/DjlTools.java @@ -404,7 +404,8 @@ public static NDArray matToNDArray(NDManager manager, Mat mat, String ndLayout) array = manager.create(buffer, shape, dataType); } else if (("NCHW".equals(ndLayout) || "CHW".equals(ndLayout)) && (nChannels == 3L || nChannels == 4L)) { // Channels-first - an OpenCV blob is defined to have the order NCHW, but an Image can only have 1, 3 or 4 channels - array = manager.create(opencv_dnn.blobFromImage(mat).createBuffer(), shape, dataType); + mat = opencv_dnn.blobFromImage(mat); + array = manager.create(mat.createBuffer(), shape, dataType); } else { // Really awkward strategy to handle channels in an uncommon place (shouldn't actually occur?) var shapeDims = shape.getShape().clone(); From f0c41c67e5e971ff0bda42adf5160589142632f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Leplat?= Date: Wed, 25 Feb 2026 14:52:59 +0000 Subject: [PATCH 2/3] Use try with resources --- src/main/java/qupath/ext/djl/DjlTools.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/qupath/ext/djl/DjlTools.java b/src/main/java/qupath/ext/djl/DjlTools.java index 8e8e524..f5670b9 100644 --- a/src/main/java/qupath/ext/djl/DjlTools.java +++ b/src/main/java/qupath/ext/djl/DjlTools.java @@ -404,8 +404,9 @@ public static NDArray matToNDArray(NDManager manager, Mat mat, String ndLayout) array = manager.create(buffer, shape, dataType); } else if (("NCHW".equals(ndLayout) || "CHW".equals(ndLayout)) && (nChannels == 3L || nChannels == 4L)) { // Channels-first - an OpenCV blob is defined to have the order NCHW, but an Image can only have 1, 3 or 4 channels - mat = opencv_dnn.blobFromImage(mat); - array = manager.create(mat.createBuffer(), shape, dataType); + try (var blob = opencv_dnn.blobFromImage(mat)) { + array = manager.create(blob.createBuffer(), shape, dataType); + } } else { // Really awkward strategy to handle channels in an uncommon place (shouldn't actually occur?) var shapeDims = shape.getShape().clone(); From 4b2c57f419c00a6314464d974962516eef4e2186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Leplat?= Date: Wed, 25 Feb 2026 14:57:57 +0000 Subject: [PATCH 3/3] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4ca1b5f..85f40f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { qupathExtension { name = "qupath-extension-djl" - version = "0.4.1" + version = "0.4.2" group = "io.github.qupath" description = "QuPath extension to use Deep Java Library" automaticModule = "qupath.extension.djl"