Creating MatOfDouble causes immediate crash on Hololens
Declaring MatOfDouble(0,0,0,0,0) causes immediate crash on Hololens, ARM64. Works fine in Unity editor.
Try-Catch not returning exception.
Creating Mat, and other wrappers (points2f etc) works fine.
Tried other allocations: .fromArray(0.0, 0.0, 0.0, 0.0, 0.0); and new MatOfDouble(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }); both also cause similar crash.
Both opencv_calib3d4100 and opencvforunity are in \Assets\OpenCVForUnity\Plugins\WSA\UWP\ARM64
Is the version you tried OpenCVForUnity 2.6.5? Does HLArUcoExample work without problems? The code in the HLArUcoExample handles initialising the MatOfDouble. https://github.com/EnoxSoftware/HoloLensWithOpenCVForUnityExample/blob/master/HLWithOpenCVExampleMRTK3/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.cs#L346
Confirming Aruco example working on Unity 2022.3.52.f1 MRTK3 example using instructions on website. Only difference is MRTK tool requested additional dependencies: [cid:7c4232ae-25d4-4614-9c4e-609db0002f6a]
Tried to initialize as follows (copied from HLArUcoExample line 363): double distCoeffs1 = 0.0;//radial distortion coefficient k1. double distCoeffs2 = 0.0;//radial distortion coefficient k2. double distCoeffs3 = 0.0;//tangential distortion coefficient p1. double distCoeffs4 = 0.0;//tangential distortion coefficient p2. double distCoeffs5 = 0.0;//radial distortion coefficient k3. distCoeffs = new MatOfDouble(distCoeffs1, distCoeffs2, distCoeffs3, distCoeffs4, distCoeffs5); Still crashes.
But: distCoeffs = new MatOfDouble(param.GetDistortionCoefficients()); (from line 327) Works fine...
EDIT: Updated to Unity 2022.3.52f1 Now method above is no longer crashing. So this seems to be a Unity 2022.3.20f1 issue.
Thank you for your reply! C
From: Enox Software @.> Sent: Thursday, February 13, 2025 5:03 AM To: EnoxSoftware/OpenCVForUnity @.> Cc: chrisamm @.>; Author @.> Subject: Re: [EnoxSoftware/OpenCVForUnity] Creating MatOfDouble causes immediate crash on Hololens (Issue #205)
Is the version you tried OpenCVForUnity 2.6.5? Does HLArUcoExample work without problems? The code in the HLArUcoExample handles initialising the MatOfDouble. https://github.com/EnoxSoftware/HoloLensWithOpenCVForUnityExample/blob/master/HLWithOpenCVExampleMRTK3/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.cs#L346
— Reply to this email directly, view it on GitHubhttps://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2656245417, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7755WG4JUIJR4SFG5HUUL2PR3ZFAVCNFSM6AAAAABXBJHEU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJWGI2DKNBRG4. You are receiving this because you authored the thread.Message ID: @.***>
Second Edit: instantiation still crashing (with null reference in VS debugger) as described in previous email…
Christian
On Feb 13, 2025, at 5:03 AM, Enox Software @.***> wrote:
Is the version you tried OpenCVForUnity 2.6.5? Does HLArUcoExample work without problems? The code in the HLArUcoExample handles initialising the MatOfDouble. https://github.com/EnoxSoftware/HoloLensWithOpenCVForUnityExample/blob/master/HLWithOpenCVExampleMRTK3/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.cs#L346
— Reply to this email directly, view it on GitHubhttps://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2656245417, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7755WG4JUIJR4SFG5HUUL2PR3ZFAVCNFSM6AAAAABXBJHEU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJWGI2DKNBRG4. You are receiving this because you authored the thread.Message ID: @.***>
Did some more trials: Unity 2022.3.52f1 (Also 2022.3.20f1), UWP Build 10240 and tried 22000. MRTK3, OpenCV, Reality Collective (service for yolov8)
This initializes and is accepted by SolvePnPRansac
Mat distortionMat = new Mat(1, 5, CvType.CV_64FC1); distortionMat.put(0, 0, new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }); MatOfDouble distortionCoef = new MatOfDouble(distortionMat);
So dynamic memory allocation not crashing for Mat construct.
The four methods below crash with no error in Unity Debug log, VS debugging generates a null exception:
distortionCoef = new MatOfDouble(0, 0, 0, 0, 0);
distortionCoef = new MatOfDouble(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 });
double distCoeffs1 = 0.0;//radial distortion coefficient k1. double distCoeffs2 = 0.0;//radial distortion coefficient k2. double distCoeffs3 = 0.0;//tangential distortion coefficient p1. double distCoeffs4 = 0.0;//tangential distortion coefficient p2. double distCoeffs5 = 0.0;//radial distortion coefficient k3. distortionCoef = new MatOfDouble(distCoeffs1, distCoeffs2, distCoeffs3, distCoeffs4, distCoeffs5);
MatOfDouble distortionCoef = new MatOfDouble(); distortionCoef.fromArray(0.0, 0.0, 0.0, 0.0, 0.0);
From: Enox Software @.> Sent: Thursday, February 13, 2025 5:03 AM To: EnoxSoftware/OpenCVForUnity @.> Cc: chrisamm @.>; Author @.> Subject: Re: [EnoxSoftware/OpenCVForUnity] Creating MatOfDouble causes immediate crash on Hololens (Issue #205)
Is the version you tried OpenCVForUnity 2.6.5? Does HLArUcoExample work without problems? The code in the HLArUcoExample handles initialising the MatOfDouble. https://github.com/EnoxSoftware/HoloLensWithOpenCVForUnityExample/blob/master/HLWithOpenCVExampleMRTK3/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.cs#L346
— Reply to this email directly, view it on GitHubhttps://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2656245417, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7755WG4JUIJR4SFG5HUUL2PR3ZFAVCNFSM6AAAAABXBJHEU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJWGI2DKNBRG4. You are receiving this because you authored the thread.Message ID: @.***>
Thank you for your report. In my test environment, ‘HLWithOpenCVExampleMRTK3/Assets/HollowLensWithOpenCVForUnityExample/HLArUcoExample’ worked without problems. In addition, the following test code was also tried, but no crashes occurred. Unity 2022.3.52f1 OpenCV for Unity 2.6.5 VisualStudio 2022 UWP Build 10.0.22621.0
distortionCoef = new MatOfDouble(0, 0, 0, 0, 0);
distortionCoef = new MatOfDouble(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 });
double distCoeffs1 = 0.0;//radial distortion coefficient k1.
double distCoeffs2 = 0.0;//radial distortion coefficient k2.
double distCoeffs3 = 0.0;//tangential distortion coefficient p1.
double distCoeffs4 = 0.0;//tangential distortion coefficient p2.
double distCoeffs5 = 0.0;//radial distortion coefficient k3.
distortionCoef = new MatOfDouble(distCoeffs1, distCoeffs2, distCoeffs3, distCoeffs4, distCoeffs5);
MatOfDouble distortionCoef = new MatOfDouble();
distortionCoef.fromArray(0.0, 0.0, 0.0, 0.0, 0.0);
Thanks for the update. The only difference is me having Reality Collective and Barracuda to the project. I wonder if any of those is conflicting with the Mat to MatOfDouble wrapper methods... Reality Collective appears as "Asset Post Processors" for OpenCV dlls... If you think this could be plausibly causing the crashes, i would post it on the Reality Collective blog... [cid:5bf5f16c-a194-4ba4-8ae0-b98e4b98a28b]
From: Enox Software @.> Sent: Sunday, February 16, 2025 8:09 AM To: EnoxSoftware/OpenCVForUnity @.> Cc: chrisamm @.>; Author @.> Subject: Re: [EnoxSoftware/OpenCVForUnity] Creating MatOfDouble causes immediate crash on Hololens (Issue #205)
Thank you for your report. In my test environment, ‘HLWithOpenCVExampleMRTK3/Assets/HollowLensWithOpenCVForUnityExample/HLArUcoExample’ worked without problems. In addition, the following test code was also tried, but no crashes occurred. Unity 2022.3.52f1 OpenCV for Unity 2.6.5 VisualStudio 2022 UWP Build 10.0.22621.0
distortionCoef = new MatOfDouble(0, 0, 0, 0, 0);
distortionCoef = new MatOfDouble(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 });
double distCoeffs1 = 0.0;//radial distortion coefficient k1. double distCoeffs2 = 0.0;//radial distortion coefficient k2. double distCoeffs3 = 0.0;//tangential distortion coefficient p1. double distCoeffs4 = 0.0;//tangential distortion coefficient p2. double distCoeffs5 = 0.0;//radial distortion coefficient k3. distortionCoef = new MatOfDouble(distCoeffs1, distCoeffs2, distCoeffs3, distCoeffs4, distCoeffs5);
MatOfDouble distortionCoef = new MatOfDouble(); distortionCoef.fromArray(0.0, 0.0, 0.0, 0.0, 0.0);
— Reply to this email directly, view it on GitHubhttps://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2661450087, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7755WKSTJUDZOZW44W2432QCL3FAVCNFSM6AAAAABXBJHEU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRRGQ2TAMBYG4. You are receiving this because you authored the thread.Message ID: @.***>
[EnoxSoftware]EnoxSoftware left a comment (EnoxSoftware/OpenCVForUnity#205)https://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2661450087
Thank you for your report. In my test environment, ‘HLWithOpenCVExampleMRTK3/Assets/HollowLensWithOpenCVForUnityExample/HLArUcoExample’ worked without problems. In addition, the following test code was also tried, but no crashes occurred. Unity 2022.3.52f1 OpenCV for Unity 2.6.5 VisualStudio 2022 UWP Build 10.0.22621.0
distortionCoef = new MatOfDouble(0, 0, 0, 0, 0);
distortionCoef = new MatOfDouble(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 });
double distCoeffs1 = 0.0;//radial distortion coefficient k1. double distCoeffs2 = 0.0;//radial distortion coefficient k2. double distCoeffs3 = 0.0;//tangential distortion coefficient p1. double distCoeffs4 = 0.0;//tangential distortion coefficient p2. double distCoeffs5 = 0.0;//radial distortion coefficient k3. distortionCoef = new MatOfDouble(distCoeffs1, distCoeffs2, distCoeffs3, distCoeffs4, distCoeffs5);
MatOfDouble distortionCoef = new MatOfDouble(); distortionCoef.fromArray(0.0, 0.0, 0.0, 0.0, 0.0);
— Reply to this email directly, view it on GitHubhttps://github.com/EnoxSoftware/OpenCVForUnity/issues/205#issuecomment-2661450087, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7755WKSTJUDZOZW44W2432QCL3FAVCNFSM6AAAAABXBJHEU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRRGQ2TAMBYG4. You are receiving this because you authored the thread.Message ID: @.***>