Hi all,
I’m developing a custom camera recorder on Magic Leap 2 using Unity and MLCamera APIs. The goal is to record front camera frames at 1920x1080, 20~30fps, and save each frame asynchronously as JPEG using ImageSharp (v2.1.0) on a background thread.
I am not doing any AR rendering—just pure RGB capture and disk saving.
However, the app consistently crashes (no exception, full freeze or exit) after around 15–20 seconds of recording, even at low FPS like 20fps. The crash happens faster at 30fps.
Setup:
- Unity Editor: 2022.3.22f1
- Magic Leap Hub: Magic Leap Hub 3
- Magic Leap 2 OS: 1.12.0
- Magic Leap SDK (OpenXR): 1.12.0
- JPEG Encoding Library: SixLabors.ImageSharp v2.1.0
- Frame format: RGBA_8888
- Saving thread: custom
Thread
, writing images and a CSV of timestamps
What I’ve tried:
- Using
ConcurrentQueue<FrameData>
for background saving - Capped queue size to prevent overload
- Verified correct disposal of ImageSharp objects and MemoryStreams
- Tried both
Texture2D.EncodeToJPG()
andImageSharp.SaveAsJpeg()
(both cause eventual crash) - Reduced resolution and JPEG quality
- Reduced FPS to 20 (still crashes after some time)
Suspected cause:
It seems the continuous memory pressure from raw RGBA frames + encoding buffers + GC load may be causing unrecoverable memory overflow, though the crash happens silently (no logs, no Unity errors).
Questions:
- Is there any known memory limit or constraint when using MLCamera + continuous capture?
- Has anyone successfully implemented long-duration camera capture with encoding?
- Is there a recommended safe approach for high-frequency frame capture and disk saving on Magic Leap 2?
- Could this be an issue with ImageSharp compatibility or native memory leaks?
Any suggestions or recommended approaches would be appreciated!
Best,
Houze Yang