none
Threading with DepthData RRS feed

  • Question

  • i am having problem by moving the depth data to another thread, it keep telling me that Cannot access a disposed object

    public DepthImageFrame depthFrame;
    void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
    using (depthFrame = e.OpenDepthImageFrame())
    {
    Thread newSliceThread = new Thread(delegate()
    {
    DepthImageFrame tempDFrame;
    tempDFrame = depthFrame;
    short[] rawDepthData = new short[depthFrame.PixelDataLength];
    if (tempDFrame != null)
    {
    tempDFrame.CopyPixelDataTo(rawDepthData);
    }
    });

    the error occur @ tempDFrame.CopyPixelDataTo(rawDepthData);
    Wednesday, January 16, 2013 6:30 PM

All replies

  • The end scope of your using statement will dispose the depth frame which you may subsequently be using on your new thread.

    Do the copy in the sensor thread and then use the copied data in your new thread instead.


    http://babaandthepigman.spaces.live.com/blog/

    Sunday, January 27, 2013 12:10 AM
  • Am I doing this correctly?

    Thread copyPixelThread = new Thread(() => 
                                  {
                                       DepthImageFrame tempDFrame;
                                       tempDFrame = depthFrame;
                                       short[] rawDepthData = new short[depthFrame.PixelDataLength];
                                       if (tempDFrame != null)
                                            tempDFrame.CopyToPixelDataTo(rawDepthData);
                                  });
    

    inside body

    copyPixelThread.Start();

    Monday, February 4, 2013 9:36 AM