graphics flickering when using values received from UDP

Hi,

I’m wrote an extremely simple iPhone app that has a bar rising and falling with a 0-255 value received via UDP. The graphics are flickering, I think because they are being continually updated, while a new value is only received from UDP every 3 milliseconds or so. I tried a few different fixes involving syncing when the line is drawn and/or the background updated, but with no luck. Here is the code:

  
  
  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){	  
	ofRegisterTouchEvents(this);  
		  
	udpConnection.Create();  
	udpConnection.Bind(1234);  
	udpConnection.SetNonBlocking(true);  
	  
	ofSetBackgroundAuto(false);  
}  
  
  
//--------------------------------------------------------------  
void testApp::update(){  
	char udpMessage[5];  
	udpConnection.Receive(udpMessage, 5);  
	sensorValue = atoi((const char*)udpMessage);  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	ofBackground(0,0,0);  
	ofSetColor(255, 0, 0);  
	glLineWidth(100);  
	ofLine(160, 380, 160, 380-sensorValue);  
}  
  

Any help would be appreciated.

Thanks,
Zach

Now you grab the value and use it to draw a bar. If there is no value, there is no bar.
Just grab the value, save it to a variable and use that to draw the bar. When there is no new value to use, it can re-use the previous value of that variable to prevent the bar from disappearing.

Well, I was already saving it to a variable. I think I was able to solve the flickering problem just by turning on vertical sync.

Thanks,
Zach