Image turns white over time

I thought I had completed my first project successfully, but have run into an issue in testing. I have several layers of images with blending modes and transparency that fade in and out over long periods of time (hours). If I run the program long enough the images turn solid white. Is this a memory issue? I intend to let it run for weeks or months. I have 16 images layered—I’m only posting a segment of the code as an example.

I’m on a Mac running OS 10.8.5 with a NVIDIA GeForce 9400M 256 MB graphics card.

Here’s the class where I change images over time:

void opaCont::setup(){
    count3 = 255;
    a = true;// start the stopwatch
//Establish time delay range------------------------------------
    rand1 = ofRandom(.1, .01);
    rand2 = ofRandom(1, .01);
    rand3 = ofRandom(.1, .01);
    rand4 = ofRandom(1, .01);

void opaCont::update(){
//Opacity Up----------------------------------------------------
    if (a){
        count4 = 0;
        opacity = count;
        count = stopwatch.elapsedSeconds() * rand1;
    if (count >= 255){
        a = false;
        b = true;

//Opacity Hold--------------------------------------------------
    if (b){
        count = 0;
        opacity = 255;
        count2 = stopwatch2.elapsedSeconds() * rand2;
    if (count2 >= 255){
        b = false;
        c = true;

//Opacity Down--------------------------------------------------
    if (c){
        count2 = 0;
        opacity = count3;
        count3 = 255 - stopwatch3.elapsedSeconds() * rand3;
    if (count3 == 0){
        c = false;
        d = true;
//Transparancy Hold---------------------------------------------
    if (d){
        count3 = 255;
        opacity = 0;
        count4 = stopwatch4.elapsedSeconds() * rand4;
    if (count4 >= 255){
        a = true;
        d = false;

And here's where I draw the images:

    void testApp::draw(){
    img1.setAnchorPercent(0, 0);
    img1.draw(450, 20);

    ofSetColor(opaCont1.opacity, opaCont1.opacity);
    img2.setAnchorPercent(0, 0);
    img2.draw(450, 20);
    ofSetColor(opaCont2.opacity, opaCont2.opacity);
    img3.setAnchorPercent(0, 0);
    img3.draw(450, 20);
    ofSetColor(opaCont3.opacity, opaCont3.opacity);
    img4.setAnchorPercent(0, 0);
    img4.draw(450, 20);

Do you ever clear the background (w/ ofBackground(0);) at the beginning of your draw loop? It seems like your image is simply accumulating over time with no opportunity to redraw and respect your blend modes …

You can also have it automatically clear with ofSetBackground(...); and ofSetBackgroundColor(...); in your setup function.

actually in OF the background is cleared every frame automatically by default

i think the problem is that you have some error in the calculation of opaContX.opacity or the blending in general that makes it grow over time till everything becomes white but that code is not in the part you posted.

try printing the values of those variables over time to check what are you setting

Thank you, Arturo. I have been printing those values and they are acting as they should. Meaning, once they reach 255 they decrease back down to 0 and start over again. That loop seems to be working fine. It makes sense that something isn’t clearing, but I’m not sure what.

Here’s my .h file:

#pragma once

#include “ofMain.h”
#include “opaCont.h”

class testApp : public ofBaseApp{
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(int x, int y, int button);
	void windowResized(int w, int h);
	void dragEvent(ofDragInfo dragInfo);
	void gotMessage(ofMessage msg);

    ofImage img1;
    ofImage img2;
    ofImage img3;
    ofImage img4;
    ofImage img5;
    ofImage img6;
    ofImage img7;
    ofImage img8;
    ofImage img9;
    ofImage img10;
    ofImage img11;
    ofImage img12;
    ofImage img13;
    ofImage img14;
    ofImage img15;
    ofImage img16;
    ofImage img17;
    ofImage img18;
    ofImage img19;
    ofImage img20;

opaCont opaCont1;
opaCont opaCont2;
opaCont opaCont3;
opaCont opaCont4;
opaCont opaCont5;
opaCont opaCont6;
opaCont opaCont7;
opaCont opaCont8;
opaCont opaCont9;
opaCont opaCont10;
opaCont opaCont11;
opaCont opaCont12;
opaCont opaCont13;
opaCont opaCont14;
opaCont opaCont15;
opaCont opaCont16;
opaCont opaCont17;
opaCont opaCont18;
opaCont opaCont19;
opaCont opaCont20;


Do you use a mac or a Pc?
check your project for memory leaks, also print your getCurrentWorkingDirectory() at the beginning of the program and then again when the problem occurs… Is the path aways the same ?