Search code examples
c++visual-studio-2010visual-studio-debugging

Visual Studio debugger fails but program runs fine when built...?


I'm working on a stereo disparity program, I have left and right images that I'm trying to read in. However I'm getting an error when trying to debug, but it works fine if I just build it...So I've just reduced the code to something very simple...

#include <bunch of opencv bits...>

using namespace std;
using namespace cv;

int main()
{
    Mat Left= imread("Left.png", 0);    //read images as grayscale
    Mat Right= imread("Right.png", 0);

    while (true) {
        imshow("Left",Left);
        imshow("Right",Right);
    }

}

Running with debug (F5) I get to the line imshow("Left",Left); and it crashes, reporting OpenCV Error: Bad flag (parameter or structure field) (unrecognized or unsupported array type) ....blah blah

Stepping through the code I can see that nothing is read stored in Left or Right

However where things get really confusing is if I just build the program (F7) and run the .exe from explorer (Misc Projects\SteroExp\Debug).... it runs completely fine.

My thoughts.... Does VS run the debug version from a different temp directory somewhere on the PC where the images aren't stored?

I'm using... W7 64bit, VS2010, C++, OpenCV 2.3.1


Solution

  • First, double-check that the working directory in Project | Properties | Debugging > WorkingDirectory is set to a directory that contains those two files.