Author Topic: TextureManager.flush()  (Read 2968 times)

Offline zed

  • byte
  • *
  • Posts: 12
    • View Profile
TextureManager.flush()
« on: July 16, 2008, 06:19:58 pm »
Why is it, that I get a NullPointerException when rendering and having flushed the texture manager beforehand. I even add new textures to the texture manager after calling TextureManager.flush(), but when I call world.renderScene(...) I get a NullPointerException which originates at "com.threed.jpct.Object3D.render(Unknown Source)". Things work fine, when I don't flush the texture manager...unfortunately I would soon run out of memory when not being able to flush the useless textures out.

Did I get something wrong with TextureManager.flush() ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: TextureManager.flush()
« Reply #1 on: July 16, 2008, 06:26:07 pm »
If your objects are still referencing the flushed textures, you'll get a crash. jPCT relies on the TextureManager to hold a reference to all the used textures.
You exactly are you trying to do? Remove unused textures from the manager? Are you using software or hardware renderer?

Offline zed

  • byte
  • *
  • Posts: 12
    • View Profile
Re: TextureManager.flush()
« Reply #2 on: July 17, 2008, 10:48:05 am »
Alright...I already thought it would be something of the kind  ;)

Anyway, here's the deal: I only want to keep a limited number of objects in my world. All of the other objects that I use are clones of this little set of 'base-models'. They are created at runtime and I want to remove them as soon as I don't need them anymore (which happens quite soon after creation). These temporary objects are potentially all textured differently, so I also want to get rid of the textures as soon as I kick out the objects. The problem here is, that I didn't find any way to remove single textures from the texture manager, so I tried flushing all textures out, which was obviously not the best idea...

I'm using Software Rendering by the way.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: TextureManager.flush()
« Reply #3 on: July 17, 2008, 01:14:37 pm »
Well...you have three options to handle this:

1.) Don't do it. I.e. reuse the texture instances that aren't used by disposed objects.
2.) Replace unused texture instances in the manager with the dummy texture. That will free the memory used by the texture but leaves a reference in the Manager. Not that nice, but not that bad either.
3.) Wait for 1.17, which will add some removal-methods to the TextureManager

The problem with removing textures is, that the coupling between the manager, the renderers and the objects is very loose. Which is a good thing in theory but it leads to the known problems. 1.17 improves this situation.

Offline zed

  • byte
  • *
  • Posts: 12
    • View Profile
Re: TextureManager.flush()
« Reply #4 on: July 17, 2008, 05:19:36 pm »
Well, looking forward to 1.17 then. Fortunately I have figured out a work-around for my problem, so I guess I won't have to wait for it.

Here's another texture-related question though: I'm loading a textured 3ds model at startup, which I want to change the textures on at runtime. I'm not adding any textures to the texture manager before loading the model, so jPCT applies a dummy texture. So far so good. Now I provide a way to interactively change the texture on that model...and it just doesn't work. To my surprise I found out that everything works just fine, when I add one of the possible textures to the texture manager before loading the model. If I do so, all the other textures, that are loaded later on work fine. I've compared pretty much every state of my application when doing it in one or the other way...everything seems to match perfectly. I'm kinda stuck here...

Edit: Not less surprising than the problem described above, is its solution. My textures had a resolution of 512x512, so I scaled them down to 256x256 and everything worked fine. I really did not expect that to be the problem...but what do I know ;)
« Last Edit: July 17, 2008, 05:55:29 pm by zed »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: TextureManager.flush()
« Reply #5 on: July 17, 2008, 07:21:36 pm »
Try to call build() or at least recreateTextureCoords() after assigning the new texture. Otherwise, the u/v mapping won't be correct when texture size changes with the software renderer.