White textures -- was FengGUI prob -- Solved


  I'm getting a wierd non-deterministic bug and I was hoping someone might have a hint to where I should look like. I'm writing a 2D game that uses simple quads with textures of them. Most of the time I run my application, I have no problem. However, 1 out of 5 times, when I start my games, all my textures are rendered as white. This problem also occurs if I run the game with a resultion box at the beginning, or if I run it in debug mode in Eclipse. After calling setTexture, I always call updateRenderState() on the quad.

  Anything I should keep a look out for?


Further investigation of the problem has led me to the following line of code:


From what I can understand, I'm loading to many different textures (around 200), even if they are all pretty small ( max 256x256, most of them 128x128 and 64x64 ). If I don't load the texture of some of the objects, then everything is fine. Ex:

      if (!this.worldObject.getName().contains("street")) {

this piece of code will reduce the number of textures by 10, and everything will load perfectly. Is there a max number of different textures I can use at any time?


There is certainly no such limit in jME, if there is any it would depend on your hardware (video RAM + amount of RAM (usually set in the BIOS)), but even 200 uncompressed 256x256 textures with mipmaps only add up to less than 70MB.

Are you using any threading?

Yeah, I'm developping using a Geforce 8600 with 256 Mb of video ram, so I would be suprised if I ran out.

My application makes heavy use of Threading. However, I made sure that all texture creation is done in the rendering thread. Hum, so if I loaded a texture outside the rendering thread, would it could a similar problem?

Anyways, your idea made me think of something. Since I'm loading my graphics objects asynchronously in the rendering thread, I have a loop similar to this in the rendering thread:

int loadCount = 0;

while (!this.gameEntityToAdd.isEmpty()) {

WorldObject object;

object = this.gameEntityToAdd.remove(0);
create texture and quad for that object
add it to the scene

if (loadCount > 30) break;


The loop only loads a maximum of 30 objects per frame render. I made to so that loading wouldn't look up the machine. This morning, after reading your message, I tried a max of 25 instead of 30 and it worked.

Is it possible to load textures too fast of JMonkey? I'm using a Quad-core machine, so I'm not sure if I'm introducing any complexities here.


Of course jME sets no such limits (why would we?), nor should OpenGL or your video hardware have any. Just keep in mind when using threading, that all collections used in jME are not thread safe, so that's not just the scenegraph, but also for example those in TextureManager.

However if you're doing all calls to TextureManager from the same thread as well that can hardly be an issue. So it sounds like something more mysterious to me…

I think I found my problem. I took a lot of debugging, but my problem disapeared when I removed a particular FengGUI window. Although I'm carefully doing everything in the rendering thread, maybe Feng isn't.


It seems like FengGUI is changing the GL state, which causes jME's state snapshot to become async. Make sure you render FengGUI components last in your rendering loop.

Oh, that's not a problem. I'm using Renderpasses and Feng is the last pass. Otherwise, I'd have lots of problems with transparencies.

You may also have to tell jME to invalidate it's context state tracking after fenggui does its thing.

Ok, that last post I did not understand.

jME keeps track of the current settings of OpenGL so that it doesn't send commands to OpenGL to set things that are already set.  FengGUI will have made changes to OpenGL's state that jME is not aware of since it is happening outside of jME (tsk, tsk…) so you need to tell jME that its "mental view" of OpenGL's current settings is not correct anymore.


Thank you!

This is exactly what is happening. I added the suggested line after the create of my FengGui widgets and all problems disappeared. From what I can gather, the bug only occurs at the creation of the widgets, even if they are not displayed. Most likely the bug is related to load textures or fonts in FengGUI. This is something any FengGUI users should know :slight_smile: