Repository: opencv/opencv_contrib

Issue #2307: RGBD failing to compile with OpenGL enabled
Created: 2019-10-24T14:55:11Z
System information (version)


OpenCV => Latest master
Operating System / Platform => Windows 10 x64
Compiler => Visual Studio 2017 x64

Detailed description
With OpenGL enabled and RGBD, it does not compile due to an error:
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(234): error C2131: expression did not evaluate to a constant
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(234): note: failure was caused by a read of a variable outside its lifetime
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(234): note: see usage of 'this'
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(206): note: while compiling class template member function 'void cv::dynafu::DynaFuImpl<cv::Mat>::drawScene(cv::OutputArray,cv::OutputArray)'
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(526): note: see reference to function template instantiation 'void cv::dynafu::DynaFuImpl<cv::Mat>::drawScene(cv::OutputArray,cv::OutputArray)' being compiled
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(275): note: while compiling class template member function 'cv::dynafu::DynaFuImpl<cv::Mat>::~DynaFuImpl(void)'
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(291): note: see reference to class template instantiation 'cv::dynafu::DynaFuImpl<cv::Mat>' being compiled
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(235): error C2131: expression did not evaluate to a constant
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(235): note: failure was caused by a read of a variable outside its lifetime
OpenCV-Contrib\modules\rgbd\src\dynafu.cpp(235): note: see usage of 'this'

The exact code that is failing is here:
float f[params.frameSize.width*params.frameSize.height];

Steps to reproduce
Compile with OpenGL and RGBD enabled.

Duplicate issue #2334: opencv_contrib\modules\rgbd\src\dynafu.cpp has err.
Created: 2019-11-07T04:32:57Z
I report below compile err and amend example.

OpenCV => 4.1.2-dev
Operating System / Platform => Windows 64 Bit
Compiler => Visual Studio 2019

Detailed description
[opencv_contrib\modules\rgbd\src\dynafu.cpp]
It source has syntax err. (234)

float f[params.frameSize.width * params.frameSize.height];
float pixels[params.frameSize.width * params.frameSize.height][3];

these are non fixed length array.
Steps to reproduce

#if 1	// AMEND
float *f = new float[params.frameSize.width * params.frameSize.height];
float *pixels = new float[params.frameSize.width * params.frameSize.height * 3];
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, f);
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, pixels);
#else
float f[params.frameSize.width * params.frameSize.height];
float pixels[params.frameSize.width * params.frameSize.height][3];
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, &f[0]);
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, &pixels[0][0]);
#endif

...

#if 1	// AMEND
delete[] pixels;
delete[] f;
#endif
#else
CV_UNUSED(depthImage);
CV_UNUSED(shadedImage);
NO_OGL_ERR;
#endif
}

What do you think about above?

Closing comment (2019-11-07T07:54:59Z): duplicate of #2307
It is better to propose patches through pull requests.

new / delete[]

Please avoid manual memory allocations. Use std::vector instead.