cscore
cscore copied to clipboard
Segfault when using CvSource
I am trying to use cscore to stream a kinect's RGB and depth data over a MJPEG connection, but when I call PutFrame, I get a segfault. Here's a gist of the C++ code I'm using: https://gist.github.com/DrWateryCat/c225e436d5761bbb21fd622c78e78972 and here's the stacktrace by valgrind:
==25030== Use of uninitialised value of size 8
==25030== at 0x5AA09F5: cv::Mat::copyTo(cv::_OutputArray const&) const (in /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9)
==25030== by 0x5EFAF60: cs::CvSourceImpl::PutFrame(cv::Mat&) (in /usr/local/lib/libcscore.so)
==25030== by 0x5EFC460: cs::PutSourceFrame(int, cv::Mat&, int*) (in /usr/local/lib/libcscore.so)
==25030== by 0x40685E: cs::CvSource::PutFrame(cv::Mat&) (cscore_oo.inl:343)
==25030== by 0x404393: main (libfreenect_opencvtest.cpp:328)
==25030==
==25030== Invalid read of size 8
==25030== at 0x5AA09F5: cv::Mat::copyTo(cv::_OutputArray const&) const (in /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9)
==25030== by 0x5EFAF60: cs::CvSourceImpl::PutFrame(cv::Mat&) (in /usr/local/lib/libcscore.so)
==25030== by 0x5EFC460: cs::PutSourceFrame(int, cv::Mat&, int*) (in /usr/local/lib/libcscore.so)
==25030== by 0x40685E: cs::CvSource::PutFrame(cv::Mat&) (cscore_oo.inl:343)
==25030== by 0x404393: main (libfreenect_opencvtest.cpp:328)
==25030== Address 0xfc2010040 is not stack'd, malloc'd or (recently) free'd
==25030==
==25030==
==25030== Process terminating with default action of signal 11 (SIGSEGV)
==25030== Access not within mapped region at address 0xFC2010040
==25030== at 0x5AA09F5: cv::Mat::copyTo(cv::_OutputArray const&) const (in /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9)
==25030== by 0x5EFAF60: cs::CvSourceImpl::PutFrame(cv::Mat&) (in /usr/local/lib/libcscore.so)
==25030== by 0x5EFC460: cs::PutSourceFrame(int, cv::Mat&, int*) (in /usr/local/lib/libcscore.so)
==25030== by 0x40685E: cs::CvSource::PutFrame(cv::Mat&) (cscore_oo.inl:343)
==25030== by 0x404393: main (libfreenect_opencvtest.cpp:328)
==25030== If you believe this happened as a result of a stack
==25030== overflow in your program's main thread (unlikely but
==25030== possible), you can try to increase the size of the
==25030== main thread stack using the --main-stacksize= flag.
==25030== The main thread stack size used in this run was 8388608.
It appears that if kinect.GetVideo() returns false, the Mat won't be initialized, which would lead to this bug.
And by "this bug", I mean it's a bug in your program, not cscore. :)
I added if (!kinect.GetVideo(rgb)) { rgb = cv::Mat::zeros(cv::Size(640, 480), CV_8UC3); }just inside the while loop, and took out the PutFrame for the depth data. Valgrind gives the same error.