Error with the thread that runs the method onManagedDraw
You have an error in the following:
have a thread that runs the following method of an object protected void onManagedDraw Entity
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) { pGLState.pushModelViewGLMatrix(); { this.onApplyTransformations(pGLState);
final SmartList<IEntity> children = this.mChildren;
if((children == null) || !this.mChildrenVisible) {
/* Draw only self. */
this.preDraw(pGLState, pCamera);
this.draw(pGLState, pCamera);
this.postDraw(pGLState, pCamera);
} else {
if(this.mChildrenSortPending) {
ZIndexSorter.getInstance().sort(this.mChildren);
this.mChildrenSortPending = false;
}
final int childCount = children.size();
int i = 0;
{ /* Draw children behind this Entity. */
for(; i < childCount; i++) {
final IEntity child = children.get(i);
if(child.getZIndex() < 0) {
child.onDraw(pGLState, pCamera);
} else {
break;
}
}
}
/* Draw self. */
this.preDraw(pGLState, pCamera);
this.draw(pGLState, pCamera);
this.postDraw(pGLState, pCamera);
{ /* Draw children in front of this Entity. */
for(; i < childCount; i++) {
children.get(i).onDraw(pGLState, pCamera);
}
}
}
}
pGLState.popModelViewGLMatrix();
}
... The problem is that this thread is still running even make a getEngine (). Stop (), that is not the same thread than the engine.
I present the following case:
If the thread that runs the method protected void onManagedDraw (end GLState pGLState, Camera pCamera end) is on this line "childCount = children.size final int ();"
childCount variable takes the value 5
then another thread is sent to delete one of the entities of this arrangement.
when the thread of the method onManagedDraw (end GLState pGLState, Camera pCamera end) is on this line
{/ * Draw children in front of This Entity. * / for (i <childCount i + +) { children.get (i). OnDraw (pGLState, pCamera); } }
children.get in method (i): Gets the exception java.lang.IndexOutOfBoundsException: Invalid index 4, size is 4
since the other thread I delete one of them while the thread did not quite do its job
This error is fatal.
I think this method should run with the engine thread
I put a (try catch) for now:
{ /* Draw children in front of this Entity. */ for (; i < childCount; i++) { try { children.get(i).onDraw(pGLState, pCamera); } catch (Exception e) { //Debug.e("Error:" + e.getCause()); } } }
I report the same request to fix it.