clear();??

hey I’m not sure if this is a bug or me being a noob, but should the following code work? It gives me a runtime crash? using the clear() function should remove the images from memory right?

In my .h:

  
#ifndef _TEST_APP  
#define _TEST_APP  
  
  
#include "ofMain.h"  
#define numberImages 150  
  
class testApp : public ofSimpleApp{  
  
public:  
  
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();  
  
};  
  
#endif  

in testapp.cpp:

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

you are using an array as a vector. try:

vectorsequence;

Hey Ding thanks!

So is the reason its crashing because when I run the clear function its removing that image completely, making "#define numberImages 150 " not true?

I haven’t quite got a grasp on vectors yet, I tried:

  
    vector<ofImage>sequence;  
    for( int i = 0; i < 10; i++ ) {  
    sequence.push_back( i );  
    string myImageName = "Comp 1_" + ofToString(i) + ".png";  
    sequence[i].loadImage(myImageName);  
    }  

With no luck, but I’m still trying!

So just making sure I have this right, the advantage with vectors is they are dynamically adjustable and the setup I had previous wasn’t? so when I was calling the clear() it was breaking.

oops sorry I didn’t notice the [1] before clear. You where using the array right. Thats what happens when you are writing and talking at the same time. I though you where doing sequence.clear() which is something completely different. When something this simple is crashing you need to follow the logic using printf. what does your debugger say? Why are you clearing the 2nd image in the array? Comment that part out and see what happens. Do a printf(“frame number: %i\n”, frame); before drawing the image and see if that is causing your error.

BTW you are also using vectors correctly :smiley:

Yea I was using an array, But thanks anyway because I finally learnt how to use vectors (somewhat), I progressed the code a little from what I posted though.

I’m trying to have images cleared and new images trickled in without my program dropping frames, I’ve been reading posts about threading and I’m going to try and avoid doing that. geesh I’m just a beginner! ha.