Can't serializate ParticleMesh

Hi,

I came across to the problem that I'm unable to serializate instance of ParticleMesh:-(. From quite a complex problem I've come to this small testing class where

java.io.NotSerializableException

is thrown at the try to serializate the ParticlMesh - even though ParticleMesh should be Serializable (according to my downloaded jME sources and your actual javadoc).



testing application:


package XXXX.YYYY;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

import com.jme.app.SimpleGame;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleMesh;

public class CombustionSerializing extends SimpleGame {

   protected void simpleInitGame() {
      
      
      ParticleMesh explosion = ParticleFactory.buildParticles("particles", 10);
      
      try {
         ObjectOutput out = new ObjectOutputStream(new FileOutputStream(new File("d:/a.ser")));
         out.writeObject(explosion);         
         out.close();
      } catch (Exception e) {
         throw new RuntimeException(e);         
      }
      
   }
   
   public static void main(String[] args) {
      CombustionSerializing test = new CombustionSerializing();
      test.start();
   }
}





Exception thrown:


SEVERE: Exception in game loop
java.lang.RuntimeException: java.io.NotSerializableException: java.nio.DirectFloatBufferU
   at XXXX.YYYY.CombustionSerializing.simpleInitGame(CombustionSerializing.java:24)
   at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
   at com.jme.app.BaseGame.start(Unknown Source)
   at XXXX.YYYY.CombustionSerializing.main(CombustionSerializing.java:31)
Caused by: java.io.NotSerializableException: java.nio.DirectFloatBufferU
   at java.io.ObjectOutputStream.writeObject0(Unknown Source)
   at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
   at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
   at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
   at java.io.ObjectOutputStream.writeObject0(Unknown Source)
   at java.io.ObjectOutputStream.writeObject(Unknown Source)
   at XXXX.YYYY.CombustionSerializing.simpleInitGame(CombustionSerializing.java:21)
   ... 3 more



I suspect it is just some stupid mistake of mine, but I can't figure out what I am doing wrong:-(

Thanks for any help

hmm… surprising answer I did not expected:-) But it returns back a little confidence in myself:-)

I'll check out your binary export/import process then. But is there any way how to combine it with normal Java serialization? Because I do not need to serialize only jME objects but also (and mostly) my own objects (however some of them contains jME objects - e.g. ParticleGeometry).

Well, you have a few options.

  1. You could provide patches to improve jME poj Serialization.  (And probably help keep it up to date.)
  2. You can implement our Savable interface in your own objects and use only that instead of Serialization.
  3. You can update the read/writeObject methods of your classes that hold jME objects to have them save the objects to a byte buffer and serialize that.

Thanks for ideas. The fourth option (which I hope will be applicable) is to think again what do I really need to serialize and make jME "problematic" objects transient.