Closed wouter-vdb closed 10 years ago
An example application in which this issue occurs can be found at https://github.com/wouter-vdb/multec-cp-processing/tree/master/android/PEA_Basics_02. When using android-core without the proposed fix, this application crashes consistently when you interact with the cube for a bit.
@codeanticode can you take a look at this–I'm not sure offhand why GL would be interfering like this.
@wouter-vdb this pull request is obsolete since the original processing-android repo has been archived. However, I tested the following test code:
public class MainActivity extends PApplet {
public int sketchQuality() {
return 2;
}
public String sketchRenderer() {
return P3D;
}
public int sketchWidth() {
return displayWidth;
}
public int sketchHeight() {
return displayHeight;
}
public void setup() {
fill(0, 255, 0);
noLoop();
}
public void draw() {
background(150);
translate(mouseX, mouseY);
rotateX(frameCount * 0.01f);
rotateY(frameCount * 0.01f);
lights();
box(200);
}
public void mouseDragged() {
redraw();
}
}
from Eclipse and didn't observe any event queue exceptions, without using the proposed changes. Please open an issue on the new processing-android repo if this issue is still happening to you. Sorry for the late response.
I had a consistent problem while handling touch-events in an application that has noLoop() in setup() and uses redraw() whenever the screen needs to be redrawn after a relevant touch-event. The exception "Nothing left on the event queue" was thrown from InternalEventQueue.remove() at arbitrary moments.
The problem was that two threads tried to dequeue the eventsQueue concurrently. The GLThread called PApplet.dequeueEvents() from PApplet.handleDraw() concurrently with the main thread which called PApplet.dequeueEvents() from PApplet.postEvent(), which is called from PApplet.nativeMotionEvent(). Below you can find a trace of a concrete situation.
I'm not deeply familiar with the implementation, but it seems that PApplet.postEvent() should not call PApplet.dequeueEvents() when either looping or redraw is true. This would be fixed as follows:
It might also be necessary to synchronize dequeueEvents() to avoid a potential race condition when postEvent() in the main thread checks the (!looping && !redraw) condition right before redraw is set to true in redraw(). The main thread would then continue with dequeueEvents() while the GLThread would at some point call handleDraw() which would call dequeueEvents() concurrently.
This trace is produced by these trace instructions: