Null pointer (NULL array pointer is passed)

Null pointer (NULL array pointer is passed)

Post by aneuryzm » Mon, 16 Jun 2008 21:48:34


Hi,

this is my code:

IplImage *image = 0;

...

if( !image ) {
image = cvCreateImage( cvGetSize(frame), 8, 3 );
image->origin = frame->origin;

}

myMethod(image);

cvShowImage( "CamShiftDemo", image );

...


Why do I receive this error ? I'm just passing the pointer image by
reference.. when myMethod finishes, I should have the same pointer to
the modified image instead it is NULL.. ?
 
 
 

Null pointer (NULL array pointer is passed)

Post by Eric Prune » Mon, 16 Jun 2008 22:34:43


XXXX@XXXXX.COM ...

hummm what error again????


myMethod probably assign NULL to image... is myMethod declared like that

void myMethod(IplImage*& img);

If you do want to change the value of the pointer, but want to change the
value of what it is pointing to (I strongly suspect it is an image...) then
declare myMethod like that

void myMethod(IplImage* img);

Anyway, if after calling myMethod, your pointer is NULL, then you proibalby
have something else wrong in you method...


-----------------

Eric Pruneau

 
 
 

Null pointer (NULL array pointer is passed)

Post by Daniel T » Tue, 17 Jun 2008 03:01:13


It took a bit, but I think I know what the problem is... Note:

void foo( int* i )
{
i = new int;
}

int main()
{
int* i = 0;
foo( i );
assert( i == 0 );
cout << "This is correct behavior.\n";
cout << "but it leaks memory.\n";
}

If the above doesn't demonstrate your problem, the please post more
code, what you gave us doesn't compile, much less run.
 
 
 

Null pointer (NULL array pointer is passed)

Post by Default Us » Tue, 17 Jun 2008 05:49:34


Please post a complete, minimal program that demonstrates the problem.





Brian
 
 
 

Null pointer (NULL array pointer is passed)

Post by Jim Langst » Tue, 17 Jun 2008 14:48:03


You did not give us the signature of cvShowImage or what the error message
is. So without cod I can only guess.
Check line 42 of your program.