Reputation: 33
I am programming little application for android in OpenGL ES 2.0. Everything was going fine, but today I implemented 2D text drawing. I just create normal canvas, write text on it and then I just load this bitmap as 2D Texture and draw it. This is method I use to change the value of the text.
public void setText(String text){
if(!this.text.equals(text)){
this.text = text;
Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bitmap);
bitmap.eraseColor(0);
Paint textPaint = new Paint();
textPaint.setTextSize(32);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0x00, 0x00, 0x00);
textPaint.getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(text, 0, bounds.height(), textPaint);
GLES20.glDeleteTextures(1, new int[]{textureHandle}, 0);
this.setTexture(bitmap);
bitmap.recycle();
}
}
I wanted to try it out, so I started to count amount of onDrawFrame calls. It works well, but at the 1045th call it freezes, then it continues for a few more frames and then the app just crashes.
I concluded, that it may be happening because of lack of free memory so I added GLES20.glDeleteTextures(1, new int[]{textureHandle}, 0); to free unnecessary texture from memory, but it haven't change anything.
Any ideas where might be problem?
Thanks Toneks
Upvotes: 1
Views: 574
Reputation: 2832
If setText() is being called by a different thread than the rest of your OpenGL ES code, then that is the problem. All call to OpenGL ES must be made from a single thread on Android. This article gives more detail on this:
Upvotes: 1