microsoft / HoloJS

Provides a framework for creating holographic apps using JavaScript and WebGL.
MIT License
1.19k stars 113 forks source link

Access violation when accessing HoloLens camera #169

Closed xabuloes closed 6 years ago

xabuloes commented 6 years ago

Hi there!

first: thank you for the amazing library that HoloJS is.

I was trying to capture a camera image from the HoloLens camera. I found the example code from a previous issue (https://github.com/Microsoft/HoloJS/issues/124) which seemed to have worked. However, when I try to access a camera image like this:

        let frame = new Image();

        frame.onload = function () {

        const canvas = document.createElement("canvas");

        // This works, so frame apparently holds certain meta data
        canvas.width = frame.width;
        canvas.height = frame.height;

        const ctx = canvas.getContext("2d");

        // Here is where the access violation happens:
        ctx.drawImage(frame, 0, 0, frame.width, frame.height);

        const imageData = ctx.getImageData(0, 0, frame.width, frame.height);

        // ... further image data processing
        }

        frame.src = "camera://local/default";

I encounter a "ThreeJSApp-Vs2017.exe: 0xC0000005: Access violation reading location XXX" here:

ImageElement.cpp

// ...

        // Lock the pixels
        WICRect allBitmapRect;
        allBitmapRect.X = 0;
        allBitmapRect.Y = 0;
        allBitmapRect.Width = m_width;
        allBitmapRect.Height = m_height;

        // This is the line where the access violation happens:
        RETURN_IF_FAILED(m_bitmap->Lock(&allBitmapRect, WICBitmapLockRead, &m_bitmapLock));

        WICInProcPointer localPixels;
        unsigned int localPixelsSize;
        unsigned int localStride;

// ...

I added all necessary capabilities to the app and using an external image (e.g. https://docs.opencv.org/3.4.0/markers.jpg) works without any issues.

Thank you in advance!

xabuloes

Almost-Done commented 6 years ago

The image buffer was being released right after the photo was acquired; the IBuffer on top of this buffer persisted, but the underlying memory was gone. Fixed by creating an IBuffer that manages its own memory.

Please try develop/fix-camera-av to verify the fix for your scenario.

xabuloes commented 6 years ago

Thank you so much for the incredible fast support! It works now.

Thumbs up to the new Microsoft/GitHub partnership! :)

nosy-b commented 5 years ago

@Almost-Done @xabuloes Yes I tried too and it works fine with the fix. Just a question, I tested successfully on SampleApps and ThreeJSApps but I can't make it work on the HoloJSWebViewer, it can't access the source "camera://local/default" through a Get. Any idea how to connect it to the webcam? (webcam and microphone capabilities added right ) Thanks!