OpenNI / OpenNI2

OpenNI2
Apache License 2.0
431 stars 895 forks source link

oniStreamDestroy called by VideoStream.destroy() freezes thread #90

Open Windowsfreak opened 9 years ago

Windowsfreak commented 9 years ago

In SimpleViewer.java, switching from Depth to IR or from IR to Depth will cause the old videoStream to be destroyed. But calling the NativeMethod oniStreamDestroy freezes the thread. (Using OpenNI-Windows-x64-2.2.0.33-Beta)

void SimpleViewerApplication.selectedStreamChanged() {

    if (mVideoStream != null) {
        mVideoStream.stop();
        mViewer.setStream(null);
        mVideoStream.destroy(); // never returns
        mVideoStream = null;
    }

public void VideoStraem.destroy() {
    NativeMethods.oniStreamDestroy(this.getHandle(), this.mCallbackHandle); // never returns
    this.mStreamHandle = 0L;
}
micuat commented 8 years ago

Hi @Windowsfreak, I encountered the same issue while sequentially playing oni recorded files (and destroy the previous oni's). Did you find any solution/workaround?

I'm using dynamic library so I cannot spot where the problem is, but at least Xcode shows

libOpenNI2.dylib`oniStreamDestroy:
    0x1487870 <+0>:  pushl  %ebp
    0x1487871 <+1>:  movl   %esp, %ebp
    0x1487873 <+3>:  pushl  %edi
    0x1487874 <+4>:  pushl  %esi
    0x1487875 <+5>:  subl   $0x10, %esp
    0x1487878 <+8>:  calll  0x148787d                 ; <+13>
    0x148787d <+13>: popl   %edi
    0x148787e <+14>: leal   0x3165b(%edi), %esi
    0x1487884 <+20>: movl   %esi, (%esp)
    0x1487887 <+23>: calll  0x14789b0                 ; oni::implementation::Context::clearErrorLogger()
    0x148788c <+28>: movl   0x30797(%edi), %eax
    0x1487892 <+34>: cmpl   $0x0, (%eax)
    0x1487895 <+37>: je     0x14878a6                 ; <+54>
    0x1487897 <+39>: movl   0x8(%ebp), %eax
    0x148789a <+42>: movl   %eax, 0x4(%esp)
    0x148789e <+46>: movl   %esi, (%esp)
    0x14878a1 <+49>: calll  0x14780f0                 ; oni::implementation::Context::streamDestroy(_OniStream*)
    0x14878a6 <+54>: addl   $0x10, %esp   <-------------- waiting for mutex here
    0x14878a9 <+57>: popl   %esi
    0x14878aa <+58>: popl   %edi
    0x14878ab <+59>: popl   %ebp
    0x14878ac <+60>: retl   
    0x14878ad <+61>: nopl   (%eax)
#0  0x9b319422 in __psynch_mutexwait ()
#1  0x01545e1d in _pthread_mutex_lock_wait ()
#2  0x0154327d in _pthread_mutex_lock_slow ()
#3  0x01543106 in pthread_mutex_lock ()
#4  0x013519a7 in xnOSLockMutex ()
#5  0x0134fd5b in xnOSEnterCriticalSection ()
#6  0x0132f160 in xnl::EventInterface<void (*)(oni_file::PlayerSource::NewDataEventArgs const&, void*)>::Unregister(XnCallbackHandleImpl*) ()
#7  0x0132ef8d in oni_file::PlayerSource::UnregisterNewDataEvent(OniCallbackHandleImpl*) ()
#8  0x0132fb77 in oni_file::PlayerStream::~PlayerStream() ()
#9  0x0132faf3 in oni_file::PlayerStream::~PlayerStream() ()
#10 0x013274cb in oni_file::PlayerDevice::destroyStream(oni::driver::StreamBase*) ()
#11 0x01484cbb in oni::implementation::VideoStream::~VideoStream() ()
#12 0x01484ab3 in oni::implementation::VideoStream::~VideoStream() ()
#13 0x01477906 in oni::implementation::Context::streamDestroy(oni::implementation::VideoStream*) ()
#14 0x01478111 in oni::implementation::Context::streamDestroy(_OniStream*) ()
#15 0x014878a6 in oniStreamDestroy ()
...