ofxImage reallocating bug?

I’ve been trying to reallocate an image to a different size and kept getting errors.

To fix it I had to do:

  
image.clear();  
image.bAllocated = false;  
image.allocate(height, width);  

Clearing the image without doing image.bAllocated = false would cause an error .

I then noticed that the ‘void ofxCvImage::clear()’ method doesn’t set bAllocated to false once it’s done clearing. This causes image.allocate to try and clear things that aren’t there.

So I changed it to:

  
void ofxCvImage::clear() {  
  
    // ------------------------------ only delete if the  
	// ------------------------------ image is really an image.  
	// ------------------------------ ie, w > 0, h > 0  
  
	if (bAllocated == true){  
		if (width > 0 && height > 0){  
			cvReleaseImage( &cvImage );  
			cvReleaseImage( &cvImageTemp );  
		}  
		delete pixels;  
		width = 0;  
		height = 0;  
  
		if( bUseTexture ) {  
			tex.clear();  
		}  
  
		bAllocated = false;  
	}  
}  
  

Now, when you try to allocate again, it won’t try and clear the image and the following can be used:

  
image.clear();  
image.allocate(height, width);  
  
//or just  
  
image.allocate(height, width);  
  

I’m not sure if this was a bug or not, but it seemed to fix my problems.

thanks cerupcat,

I committed the fix.