Q:

Bad Ptr when passing string reference as argument

I've been trying to understand why the following code gives me a bad pointer on the string 'filename':
Mat imread(const string& filename, int flags) { 
    // some code returning a Mat object 
}

int main() {
    string s = "test.jpg";
    imread(s, 0);
}

I've debugged step-by-step and all I've got was that before entering imread, the string was fine (I was able to inspect each element of it), but afterwards it was impossible to do so, and the debugger accused a Bad Ptr. I'm not sure I understand why that happens.
Just so you know, I'm using Visual Studio 2008 and OpenCV 2.2.
EDIT: I have indeed forgotten to say one important thing, that was essential for me to solve this issue: I was writing this code on a .cu file, therefore being compiled by nvcc in a first instance.

A:

Writing debuggers for native code is a non-trivial task. There is no 1 to 1 correspondence of the machine code to the source code. It's common for the debuggers to give such misleading information, it doesn't mean though that the actual value is invalid. Also make sure that you compile with debug info turned on and all optimization turned off.
Note: when you step into a function, the stack-frame may not be initialized yet. Doing one more step may show the correct parameters.

A:

I solved this issue by separating in different files all OpenCV code from the code that involved the CUDA extension. Therefore, imread was now being called from a .cpp file and everything that involved CUDA was on different .cu and .h files.
Correct me if I'm wrong, but I don't think this is supposed to be that way, maybe it's a bug.

