Loading...
Logo
Processing Forum
Hi all, 

I'm finding this happens with most of my sketches.

There is a sort of "dragging" effect, every few seconds, where the points appear to skip back for a frame.
I've put together this simple sketch to demonstrate what I mean.

If my code is causing it, i'd be keen to know why, but it seems to happen more when there is less going on, like it's the opposite to slowdown. Can anyone explain it? perhaps it's just my system but I don;t think so...

Thanks in advance

Dave

int offset = 60;
int numberOfComponents = 14;
int speed = 5;

Component[] pointComponents = new Component[numberOfComponents];

int[] yValues = {
10, 20, 50, 150, 150, 30, 90, 150, 30, 70, 150, 30, 90, 90
};

void setup() {
size(800, 180);
frameRate(30);

for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i] = new Component(i*offset, yValues[i]);
}
}

void draw() {
background(0);
for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i].run();
}
}

class Component {

PImage componentGraphic;
int x, y;
String a;

Component(int offsetX_, int yPos_) {
x = offsetX_;
y = yPos_;
}

void run() {
display();
move();
cycle();
}

void display() {
stroke(255);
point(x, y);
}

void cycle() {
if (x == -60) {
x=width;
}
}

void move() {
x=x-speed;
}

void listen() {
}
}

Replies(4)

Re: Visual glitch?

2 years ago
They don't "skip back", but are halted for a fraction of second, and eye makes it look like a back movement.
This is because Java is a garbage collected (GC) language, and sometime the GC "stops the world" to reclaim used memory. You don't create new objects, but I think Java does, behind the scene, despite Processing being careful about avoiding to create objects as well.

Re: Visual glitch?

2 years ago
BTW: There is a small mistake in the cycle() method:

if (x == -60) {

should read

if (x <= -60) {

since if you set the variable speed to other values than 5, the upper condition never might come true.

Re: Visual glitch?

2 years ago
Thanks for the replies - Am I to take it that this appearance of stuttering is unavoidable then?
Hi, 

I have now done a lot of reading about the various types and behaviors of the Java Garbage Collector, how to avoid collection and how to re-allocate as much of what you possibly can within a sketch. I've read that an incremental GC is possibly a better solution for real-time graphical applications such as games. I've also looked extensively at the Visual VM, and DDMS when using Processing for Android.

But, this sketch keeps coming back to haunt me. I cannot imagine optimizing and tweaking more complicated sketches or applications if I can't stop the GC from pausing so frequently in such a simple sketch.

Any kind of push in the right direction would be genuinely appreciated.

Thanks

Dave