Reputation: 11
I'm trying make save/load game mechanism in my Libgdx game. I'm using Kryo to write objects. Graph of objects is very large and complex. I'll not post whole code because it's too much of it. It contains many ArrayLists. Objects having many references to other objects. Many fields are excluded from serialization by transient keyword because they containing Textures, Pixmap etc. SaveGame class:
package save_game;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import data.GameDataBase;
public class SaveGame {
private GameDataBase gameDB;
private Kryo kryo;
private KryoUtil kryoUtil;
public SaveGame(GameDataBase gameDB) {
this.gameDB = gameDB;
kryoUtil = new KryoUtil();
kryo = kryoUtil.getKryo();
}
public void save() throws FileNotFoundException {
kryo.setReferences(true);
Output output = new Output(new FileOutputStream("testfile"));
kryo.writeClassAndObject(output, gameDB);
output.close();
}
}
When running method save i get error message which repeats itself filling whole console:
at com.esotericsoftware.kryo.serializers.ReflectField.write(ReflectField.java:71) at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:108) at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) at com.esotericsoftware.kryo.serializers.ReflectField.write(ReflectField.java:71) at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:108) at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:644) at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:362) at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:326)
None exception is reported in console. It looks like stackoverflow, but what causing the error i can't find out. I've increased vm stack size -Xss300m and it didn't fixed the issue. Any ideas what i did wrong?
Upvotes: 0
Views: 1577
Reputation: 11
I've found solution. I could not get full error message. So i've set vm arg -XX:MaxJavaStackTraceDepth=200000000 to display full trace. Some classes were not register in Kryo. I registered the missing classes and the write operation was successful. I had similar problems when reading the written file, but this time the error message was full in a few cases. Missing non args constructor. In those cases where the error message was not full, I've run the game in debug mode and caused crash to provoke breakpoint hit in LwjglApplication.initialize() method. There I've investigated field KryoException.trace. Also missing non args constructor. I'm not sure why the error message in console was not full, but I'm guessing that too many references to many objects which had references to other objects caused that.
Upvotes: 1