Scrolling loaded images

I am making a display which loads a directory of images and continually scrolls them left across the screen. The first image x position starts at the screen width then subsequent images are placed at the previous image x position plus its width. Once an image has completely left the screen, its x position is reset to the original position and then the x position is not updated until the last image in the array has been fully displayed on screen. This all works beautifully, however… Once the images have scrolled round once, when the last few images are drawn, random gaps start to appear. I have tried several methods of reseting the x position, for example, adding up the total width of the images and placing them at the back once they’ve been displayed. However, this only moves the gaps to a different place. The gaps don’t appear at the beginning or end, just in weird places that I can’t see a logical reason for. I have changed the data type of the x position to a double to see if it was an accumulative inaccuracy in the calculation, but this made no difference. I Would really appreciate some help as I have no idea where to go from here… THANKS!

/****************** EDIT ********************/
So, having logged some stuff to the console, I can see that it is after the 100th image that things screw up.

image 100 (correct)
the reset position is is 98627.000000
the origin is is 98627.000000

image 101 (wtf?)
the reset position is is -1242.000000
the origin is is 99108.000000

Main

  
void testApp::setup() {  
    //hasStarted = false;  
      
    width = ofGetWidth();  
      
    waveBackground.loadImage("background/wave_background_4095x600.jpg");  
                       
    // read the directory for the images  
    // we know that they are named in seq  
    ofDirectory dir;  
      
    int nFiles = dir.listDir("plops");  
    if(nFiles) {  
        images.reserve(dir.numFiles());  
        for(int i=0; i<dir.numFiles(); i++) {   
              
              
            // add the image to the vector  
            string filePath = dir.getPath(i);  
            Image img;  
            images.push_back(img);  
            images.back().image.loadImage(filePath);  
              
        }  
          
    }   
    else printf("Could not find folder\n");  
      
    for (int j = 0; j < images.size(); j++) {  
        images[j].setWidth(images[j].image);  
        images[j].setHeight(images[j].image);  
          
        if (j==0) {  
            images[0].x = width;  
        } else {  
            images[j].x = images[j-1].x + images[j-1].width;  
        }  
          
        images[j].setOrigin(images[j].x);  
           
        images[j].speed = 50;  
    }  
      
  
    // set the app fps   
    appFPS = 30;  
    ofSetFrameRate(appFPS);  
}  
  
//--------------------------------------------------------------  
void testApp::update() {  
      
    for (int i = 0; i < images.size(); i++) {  
        if (images[i].x + images[i].width > 0 && images[i].doUpdate) {  
            images[i].update();  
        }  
    }  
    lastX = images.back().x + images.back().width;  
   
}  
  
//--------------------------------------------------------------  
void testApp::draw() {  
      
    // we need some images if not return  
    if((int)images.size() <= 0) {  
        ofSetColor(255);  
        ofDrawBitmapString("No Images...", 150, ofGetHeight()/2);  
        return;  
    }  
  
      
    waveBackground.draw(0,0);  
      
    ofEnableAlphaBlending();  
      
    for (int i = 0; i < images.size(); i++) {  
        if (images[i].x + images[i].width > 0 && images[i].x < width) {  
            images[i].draw();  
        }  
          
        if (images[i].x + images[i].width < 0) {  
            images[i].doUpdate = false;  
            images[i].x = images[i].origin;  
        }  
          
        if (lastX < width) {  
            images[i].doUpdate = true;  
        }  
          
    }  
      
    ofDisableAlphaBlending();  
}  
  
  

Image class

  
Image::Image() {  
      
    y = (ofGetHeight() / 2 - height / 2) - 150;  
    doUpdate = true;  
}  
  
void Image::setWidth(ofImage img) {  
    width = (img.getWidth()) + 6;  
}  
  
void Image::setHeight(ofImage img) {  
    height = (img.getHeight()) + 6;  
}  
  
void Image::setOrigin(float _origin) {  
    origin = _origin;  
}  
  
void Image::update() {  
    x -= speed;  
}  
  
void Image::draw() {  
    image.draw(x, y);  
}