Nullpointer when preloading particle effects

Hey everone! I'm new to both jME and the forums. Love the engine, keep up the good work.



I've been working on a simple preloading system for a small game of mine.

Everything seems to be working so far, except I'm having a problem loading .JME binary files containing particle meshes. I've managed to load models (also in .JME binary format) in the same way with no problems.



I get a NullPointerException when I try calling the following method before the game initialization (ie: before the SimpleGame's simpleInit method).

When I call this from the simpleInit method it works fine.

The NPE is being thrown from the BinaryImporter line.



Is there any way I could perform this before initializing the game? Or is there some other way of preloading particles from a file?



(using the same loading code as RenParticleEditor)

posting the stack trace would be helpful

The null pointer indicates no display system or renderer is available at the point in the code.  This is needed to create the correct renderstates when loading the particles.  So, the solution is to not load until after the display is created.  Or, you can use a DummyDisplaySystem if you are not planning on creating a display.

What type of file do you pass in "URL url". ".jme" generated by Particles Editor can be used?

Yes.

But how do I know what type of object RenParticleEditos is wrinting in the .jme file? Is it ParticleMesh?

First off, in general when loading a .jme file, you can almost always safely refer to it as a Spatial.  Otherwise, use instanceof to check.

In the case of RenParticleEditor, the top level item is a Node.  Under that node is 1 or more ParticleGeometry objects, the type of which will depend on whether you chose Line particles, Point particles, etc.

While saving my particles, i'm referencing an image for the texture of the particle.

but while loading the jme file i got the following error:


java.io.FileNotFoundException: resourcesmodelsflaresmall.jpg (The system cannot find the path specified)
   at java.io.FileInputStream.open(Native Method)
   at java.io.FileInputStream.<init>(FileInputStream.java:106)
   at java.io.FileInputStream.<init>(FileInputStream.java:66)
   at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
   at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
   at java.net.URL.openStream(URL.java:1007)
   at com.jme.util.TextureManager.loadImage(Unknown Source)
   at com.jme.util.TextureManager.loadImage(Unknown Source)
   at com.jme.util.TextureManager.loadTexture(Unknown Source)
   at com.jme.util.TextureManager.loadTexture(Unknown Source)
   at com.jme.image.Texture.read(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.readObject(Unknown Source)
   at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(Unknown Source)
   at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(Unknown Source)
   at com.jme.util.export.binary.BinaryInputCapsule.readSavableArrayList(Unknown Source)
   at com.jme.scene.state.TextureState.read(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.readObject(Unknown Source)
   at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(Unknown Source)
   at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(Unknown Source)
   at com.jme.scene.SceneElement.read(Unknown Source)
   at com.jme.scene.Spatial.read(Unknown Source)
   at com.jme.scene.Geometry.read(Unknown Source)
   at com.jmex.effects.particles.ParticleGeometry.read(Unknown Source)
   at com.jmex.effects.particles.ParticleMesh.read(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.readObject(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
   at bombastic.jme.effects.ParticleExplosionUI.prepareExplosion(ParticleExplosionUI.java:37)
   at bombastic.jme.effects.ExplosionUI.<init>(ExplosionUI.java:29)
   at bombastic.jme.effects.ParticleExplosionUI.<init>(ParticleExplosionUI.java:28)
   at bombastic.jme.effects.PoolEffect.<init>(PoolEffect.java:37)
   at bombastic.jme.effects.PoolEffect.getPoolEffect(PoolEffect.java:81)
   at bombastic.TestExplosion.simpleInitGame(TestExplosion.java:68)
   at bombastic.jme.SimpleFixedGame.initGame(SimpleFixedGame.java:212)
   at com.jme.app.FixedFramerateGame.start(Unknown Source)
   at bombastic.TestExplosion.main(TestExplosion.java:44)



i use the following

      URL url = DiceUI.class.getClassLoader().getResource("resources/models/DiceExplosion.jme");
      try
      {
         Object particleNode = BinaryImporter.getInstance().load(url);
         _explosionNode.attachChild((ParticleMesh)particleNode);
         _explosionNode.setLocalScale(0.01f);
      }
      catch(Exception e)
      {
         trace.println("damn exceptions:" + e.getMessage());
      }


the .jme file as been saved in "." directory then moved to "resources/models/DiceExplosion.jme" where the texture is located. Any idea ?

Anybody to help me on that subject ?

There could be a number of reasons, for example, upper-vs-lower case letters in the filename, the texture lookup not using the same resource loader you are using to open the file, etc. 

The case is ok as i've double checked. Now how to be sure to use the same resource loader as the one used by the jme loader ?

Well, for example, where is the files in relation to your working directory?  DiceUI.class.getClassLoader().getResource(…) can find something deep in the tree of your source whereas the textureloader is going to be looking for things relative to the working directory.



Edit: Nevermind with getClassLoader()  it will be looking relative to working directory too I believe…  :confused: