Author Topic: Config.maxTextures doesn't work as assumed  (Read 2564 times)

Offline say-V

  • byte
  • *
  • Posts: 6
    • View Profile
Config.maxTextures doesn't work as assumed
« on: October 25, 2011, 04:19:42 pm »
By default Conf.maxTextures = 64 that's clear. But I assumed this means that there can not be more textures than 64 at a time, but sure can be more in the whole lifecycle of the app. In my case I use a lot of textures, but not at a time, I also unload and remove old textures that I don't need anymore. I have never more than ~30 textures in use at a time, but nevertheless after some time I get an error.
Quote
ERROR: Too many textures added to the TextureManager. Adjust Config.maxTextures!

Pseudo-Code for testing:
Code: [Select]
for i = 0 ... 100
   textureName = "label" + i
   textureManager.addTexture(textureName, createTextureFromString(textureName)
   testPlane.setTexture(textureName)  // so it gets uploaded to GPU
   if (i >= 30) {
      textureManager.removeAndUnload("label" + (i - 30), fb)  // should remove and unload from GPU and TextureManager
      Logger.log(textureManager.getTextureCount())
   }
end for

Of course I could increase Conf.maxTextures. But that doesn't change the root problem, so I thought I post it.

btw:
Quote
The manager wil increase the value if needed
there is a spelling mistake (and I think the manager doesn't increase the value, otherwise there would be no error I assume).

I'm already looking forward to finish my project and post it here on the board  :D
jPCT-AE is a great engine!!!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Config.maxTextures doesn't work as assumed
« Reply #1 on: October 25, 2011, 05:12:22 pm »
Which version of jPCT-AE are you using? 1.24 should actually fix this problem. That aside, it's better to use replaceTexture() instead of removeTexture()/addTexture() if possible.

Offline say-V

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Config.maxTextures doesn't work as assumed
« Reply #2 on: October 25, 2011, 06:29:44 pm »
A side note: in the meantime I tried to use Config.maxTextures = Integer.maxValue; but this approach failed already on launching because it seems that an array with length Config.maxTextures is allocated by TextureManager. So using big values for this variable is really not a good idea.

I'm using 1.24 now and it works almost perfect. But when I set eg. Config.maxTextures = 10; and I add more than 10 textures I don't get a error from the texture manager anymore, but instead an ArrayIndexOutOfBoundsException from runtime directly. Maybe you want to fix that.

replaceTexture() -> thanks for the tipp!



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Config.maxTextures doesn't work as assumed
« Reply #3 on: October 25, 2011, 08:29:22 pm »
Opps...that shouldn't happen. I'll look at it...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Config.maxTextures doesn't work as assumed
« Reply #4 on: October 25, 2011, 08:36:24 pm »
I can't verify this problem...can you please post a complete stack trace?

Offline say-V

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Config.maxTextures doesn't work as assumed
« Reply #5 on: October 26, 2011, 02:12:52 pm »
No, I'm sorry, I can't. I don't know what happend, I can not verify the problem myself either today. But I was conscious yesterday and I'm sure the Exception happened. I used Config.getVersion() to verify the version and it was 1.24 after updating the .jar file.

Now I set Config.maxTextures = 20; and I tried to add up to 200 textures with no problem at all, sick. The value of Config.maxTextures never changes during this process.

I will come back to that in case I find out anything. Thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Config.maxTextures doesn't work as assumed
« Reply #6 on: October 26, 2011, 09:45:14 pm »
Maybe a threading issue? Maybe you are adding textures in another thread than the rendering thread? If so, don't so that.

Offline say-V

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Config.maxTextures doesn't work as assumed
« Reply #7 on: October 27, 2011, 11:29:07 am »
Exactly, I do it in another thread. I think that also causes the flickering I have sometimes. It sounds similar like this topic. Maybe this is also a multi-threading realted problem.
My player consists of more objects and when I move him around in navigation thread, it happens that one object is already further than the others. (My workaround was that I found the mergeObjects() method  ;) )

I read a lot in the board now, and I you mentioned sometimes that jPCT-AE is not thread safe. What does this exactly mean? I saw a video from Google IO, they mentioned that it is wise isolate navigation and game logic in different threads than rendering. After my classes got bigger and bigger I tried this approach also. It works quite well beside the problems I have already mentioned. Next I tried to synchronize the move() method of navigation thread with the onDrawFrame() method of rendering thread. I thought this should help, but it didn't work, the navigation thread was blocked forever. Beside I think I get much overhead through syncronizing all this stuff in the end. Now I'm thinking of merging all in one thread/class again.

I know this doesn't fit to this thread-topic anymore, but could you (or someone professional else) give an advice how a good architecture could look like for a (big) jPCT-AE realtime project? This would be simply awesome  :) !

Edit: I started a new topic on that one.
« Last Edit: October 27, 2011, 11:48:17 am by say-V »