Bug, imshow throws Null pointer exception when it should throw out-of-memory

asked 2014-06-11 06:12:47 -0500

When my GPU runs out of RAM it throws a NULL pointer exception when calling imshow. Shouldn't I get a out-of-memory exception? I don't get that error when I'm using a 1MB matrix (or other sizes which would have enough space). I'm using a notebook with Windows 7 64-Bit, 4GB RAM and a GPU with 1 GB RAM, Qt Creator 2.7.2 (based on Qt 5.1.0 (32bit)) with MinGW.

#include <Texture/TextureManager.h>
#include <opencv2/opencv.hpp>
int main(int argc, char** argv) {

    std::cout << "Create 1GB char-data." << std::endl;
    char *srcData = new char[1024*1024*1024];
    std::cout << "Create a cv::Mat out of this data." << std::endl;
    cv::Mat src (1024*1024, 1024, CV_8S, srcData);
    std::cout << "Create a named window (with a dumb name)." << std::endl;
    cv::namedWindow("ZOMFG, a bug");
    std::cout << "Show the (random) image." << std::endl;
    cv::imshow("ZOMFG, a bug", src);
    std::cout << "Finished" << std::endl;

    cv::waitKey(0);

    return 0;
}

I get the following result:

Create 1GB char-data.
Create a cv::Mat out of this data.
Create a named window (with a dumb name).
Show the (random) image.
OpenCV Error: Null pointer (The matrix has NULL data pointer) in cvGetMat, file ...\OpenCV2\opencv\sources\modules\core\src\array.cpp, line 2387
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'cv::Exception'
  what():  ...\OpenCV2\opencv\sources\modules\core\src\array.cpp:2387: error: (-27) The matrix has NULL data pointer in function cvGetMat
edit retag flag offensive close merge delete