Can't load serialized object Android

Started by cocojack, March 24, 2013, 11:49:27 AM

Previous topic - Next topic

cocojack

Hello, im working on some tutorials to get into JPCT-AE.
At the moment i'm trying to load a texture of an airplane into my android app.

I've downloaded a model of an airplane and serialized it with jBrush v0.3.


my code:

         ZipInputStream serStream = new ZipInputStream(masterContext.getResources().openRawResource(R.raw.dassault_mirage));
         try{serStream.getNextEntry();}
         catch(IOException e)
         {throw new RuntimeException(e);}
         airplane = Loader.loadSerializedObject(serStream);
         airplane.setTexture("texture");


on start, this code part gets a runtime exception:
java.lang.RuntimeException: [ 1364121233198 ] - ERROR: Can't deserialize object: length=256; regionStart=-1; regionLength=257

at airplane = Loader.loadSerializedObject(serStream);

i dont know what I did wrong this time :(
greezs coco

EgonOlsen

Looks like as if something is wrong with your input stream. Can you post the full stack trace?

cocojack

#2
Attributes

private Object3D airplane = null;




@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
Logger.log("onSurfaceChanged");
Logger.setLogLevel(Logger.LL_DEBUG);

if (fb != null) fb.dispose();

fb = new FrameBuffer(gl, width, height);

if (masterActivity == null)
{
world = new World();
world.setAmbientLight(120, 120, 120);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
SimpleVector sv = new SimpleVector();
sv.set(0,-100,-100);
sun.setPosition(sv);

Texture texture = new Texture( BitmapHelper.rescale(BitmapHelper.convert(masterContext.getResources().getDrawable(R.drawable.dassault_mirage)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

ZipInputStream serStream = new ZipInputStream(masterContext.getResources().openRawResource(R.raw.dassault_mirage));
Logger.log("loaded serStream");
try{
serStream.getNextEntry();
Logger.log("loaded next entry");
}
catch(IOException e)
{
Logger.log("io-Exeption");
throw new RuntimeException(e);
}
Logger.log("loading serialized obj");
airplane = Loader.loadSerializedObject(serStream);
Logger.log("setting texture");
airplane.setTexture("texture");



world.addObject(airplane);
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(airplane.getTransformedCenter());
sv.set(airplane.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();
}
}


content of serStream :

serStream ZipInputStream  (id=830038260848)
buf (id=830038130704)
charBuf (id=830038138048)
closed false
crc CRC32  (id=830038130184)
currentEntry null
entriesEnd false
entryIn 0
eof false
hasDD false
hdrBuf (id=830038131240)
in PushbackInputStream  (id=830038087616)
inf Inflater  (id=830038131336)
inRead 0
lastRead 0
len 0
nameBuf (id=830038136280)
nativeEndBufSize 0

debug output:

03-24 12:53:29.515: E/AndroidRuntime(8727): FATAL EXCEPTION: GLThread 12093
03-24 12:53:29.515: E/AndroidRuntime(8727): java.lang.RuntimeException: [ 1364126009517 ] - ERROR: Can't deserialize object: length=256; regionStart=-1; regionLength=257
03-24 12:53:29.515: E/AndroidRuntime(8727): at com.threed.jpct.Logger.log(Logger.java:189)
03-24 12:53:29.515: E/AndroidRuntime(8727): at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:244)
03-24 12:53:29.515: E/AndroidRuntime(8727): at com.threed.jpct.Loader.loadSerializedObject(Loader.java:93)
03-24 12:53:29.515: E/AndroidRuntime(8727): at com.securitywarefare.engin.MyRenderer.onSurfaceChanged(MyRenderer.java:101)
03-24 12:53:29.515: E/AndroidRuntime(8727): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
03-24 12:53:29.515: E/AndroidRuntime(8727): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)



could it be that the files doesnt load correctly to my android device?

cocojack

It works now, may anyone can explain what is the difference between those:

terrain = Loader.loadSerializedObject(masterContext.getResources().openRawResource(R.raw.dassault_mirage));
terrain.setTexture("texture");

forgot to mention that I use this document to get in jpct-ae : http://www.jpct.net/forum2/index.php?topic=2667.0