"Too many textures added to the TextureManager."

Started by Darkflame, September 17, 2010, 08:06:45 PM

Previous topic - Next topic

Darkflame

I'm trying to have lots of updateing textures in my project,and keep running into this error;

AndroidRuntime(22498): java.lang.RuntimeException: - ERROR: Too many textures added to the TextureManager. Adjust Config.maxTextures!

Heres my code for updating the texture;

private void updatedTexture(String Texturename, String text) {

Log.i("add", "update texture triggered with:"+Texturename+"|"+text);

paint.setColor(Color.BLACK);

Bitmap.Config config = Bitmap.Config.ARGB_8888;
FontMetricsInt fontMetrics = paint.getFontMetricsInt();
int fontHeight = fontMetrics.leading - fontMetrics.ascent
+ fontMetrics.descent;
int baseline = -fontMetrics.top;
int height = fontMetrics.bottom - fontMetrics.top;

// have to add multiline support here
Bitmap charImage = Bitmap.createBitmap(closestTwoPower((int) paint
.measureText(text) + 10), 32, config);

Canvas canvas = new Canvas(charImage);
canvas.drawColor(Color.WHITE);
canvas.drawText(text, 10, baseline, paint); // draw text with a margin
// of 10

TextureManager tm = TextureManager.getInstance();

Texture testtext = new Texture(charImage, true); // the true specifys
                        // the texture has
// its own alpha. If
// not, black is
// assumed to be
// alpha!

//

if (tm.containsTexture(Texturename)) {

Log.i("add", "updating texture="+Texturename);

tm.removeAndUnload(Texturename,fb);

Log.i("add", "updated texture="+Texturename);

tm.addTexture(Texturename, testtext);

} else {
tm.addTexture(Texturename, testtext);
}

}



Note the last bit.

Surely this should ensure the texture is replaced and thus not cause too many to form :? Instead I get my textures either turning completely white, or causing this error. (or both) after a few updates.

EgonOlsen

That's most likely caused by the way remove in the tm works. It removes the texture itself but doesn't free the slot in all cases. If you want to replace a texture in the tm, why don't you use the replaceTexture-method? A faster way (if appropriate) would be to use an ITextureEffect to update the texture's content.

Darkflame

QuoteIf you want to replace a texture in the tm, why don't you use the replaceTexture-method?

I did try the replace function at firstit didn't seem to make any difference above was my attempt to "make sure".

QuoteIf you want to replace a texture in the tm, why don't you use the replaceTexture-method? A faster way (if appropriate) would be to use an ITextureEffect to update the texture's content.

I was already quite impressed with the speed to be honest, but if it results in progressively increasing memory use, or some internal allocation being used up, Its not something I can live with.

To be honest, I know nothing of ITextureEffect or if it will be appropriate, so I'll just describe my scenario and you can see if it would fit;

* At runtime data is downloaded from the server.
* This data is used to position billboard-planes in the field of view with text on.
* At any time, new information can come from the sever changing the text on any of the billboard-planes.

Each billboard plan has an unique ID in its name field that matches its texture. So the method above is supposed to just take the next text and replace the old texture with it.
Its rather crude at the moment in regards to the size/placement of the text, but I'll fix that neater later.

Thanks



EgonOlsen

#3
I don't see how a replace can have the same problem. It doesn't add a new texture, so it can't possibly trigger that error message. It might cause the gpu to run out of texture space though, because it doesn't force the old texture to be unloaded. Try to do an unload (but no remove) on your old texture and replace it with the new one afterwards.

Darkflame

I figured it out. It was a bit of a mis-direction issue - I wrongly identified the area of code going wrong.
It seems my object being "updated" was actually getting duplicated, lots of objects were appearing in the same place, and as they were all facing sprites this was unnoticeable. (interestingly the most recent object showed up at the "front").

So I'm guessing lots of identical textures were created rather then being replaced. (as my code looks at the object name to determine an update rather then a new texture).

Anyway,as you suggested I'm now using a unload followed by a replace.
This seems to work with at least 50 or so object updates now, so I think its working fine :)