a small bug in ofImage::clear()

ok, so I found that if you clone an image, then clear it, and then try to clone again, the application crashes.

offending code:

void testApp::setup(){  
	cloned = bikers;  
    cloned = gears;  

I found that clear was not cleaning the underlying bmp, so you just have to add

bmp 					= NULL;  

to ofImage::clear()

so it ends up like this

void ofImage::clear(){  
	if(isValid() && bFreeImageInited) {  
		// zach - I added "if (bFreeImageInited)" since  
		// app runner might kill freeImage, so images killing themselves might not  
		// want to call anything freeImage related.  
	if (imgPixels != NULL && bAllocatedPixels == true){  
		delete [] imgPixels;				// delete anything that might have existed  
		bAllocatedPixels = false;  
	bmp 					= NULL; //<---  
	width = height = bpp = 0;  
	type 					= OF_IMAGE_UNDEFINED;  
	bUseTexture 			= true;		// the default is, yes, use a texture  
	bAllocatedPixels		= false;  

hope it makes sense.

Hi I’m not sure I’m writing this correctly but I cant seem to get the image clear() function to work when I run the following code I get a runtime crash:

In my .h:

#ifndef _TEST_APP
#define _TEST_APP

#include “ofMain.h”
#define numberImages 150

class testApp : public ofSimpleApp{


ofImage sequence[numberImages];
int frame;
void setup();
void update();
void draw();

void keyPressed (int key);
void keyReleased (int key);

void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased();



in testapp.cpp:

#include "testApp.h"  
void testApp::setup(){  
    frame = 1;  
    for (int i = 0; i < numberImages; i++){  
    string myImageName = "Comp 1_" + ofToString(i) + ".png";  
void testApp::update(){  
     if (frame < 50){  
     frame ++;  
     if (frame > 10){  
void testApp::draw(){  
        sequence[frame].draw(0, 0);  

did you find a workaround?

i’m running into the same problem on osx 10.5.2 with oF 0.05. but not on 10.4.1.

the crash seems to be caused by FreeImage_Unload.