Hi,
I have a problem with serialization. Some users of my game experience crashes when attempting to serialize or deserialize the world. One user reported a stackoverflowerror while another user reported a massive fps frop after saving followed by a crash 2 seconds later.
I can’t replicate this crash because it seems to work perfectly fine for most users including myself.
here is the code:
public static void saveWorld(R_Object[] groundtile_list, String foldername, String filename, String extension)
{
boolean savedsucces = false;
String temp_pathname = foldername+"\\"+filename+"_temp"+extension;
try (FileOutputStream fos = new FileOutputStream(temp_pathname)) {
//File outputsteam saves to file
//objectoutputstream does serialization
try (ObjectOutputStream out = new ObjectOutputStream(fos)) {
out.writeObject(groundtile_list);
savedsucces = true;
}
catch(IOException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null, "objectoutputstream error: "+e.toString());
}
catch(Exception e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null, "objectoutputstream error: "+e.toString());
}
}
catch(IOException e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null, "fileoutputstream error: "+e.toString());
}
catch(Exception e) {
System.out.println(e.toString());
JOptionPane.showMessageDialog(null, "fileoutputstream error: "+e.toString());
}
if (savedsucces == true) {
try {
File folder = DopplerMath.getFolder(foldername+"\\");
File filetemp = DopplerMath.getFile(folder, filename+"_temp", extension);
//delete old save if it exist
File fileold = DopplerMath.getFile(folder, filename, extension);
if (fileold != null) {
fileold.delete();
}
filetemp.renameTo(new File(foldername+"\\"+filename+extension));
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, "failed to save world: "+e.toString());
}
}
}
public static R_Object[] loadWorld(String filename)
{
R_Object[] groundtilelist = null;
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename))) {
groundtilelist = (R_Object[]) in.readObject();
return(groundtilelist);
}
catch(IOException | ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "failed to load world: "+e.toString());
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, "failed to load world: "+e.toString());
}
return(groundtilelist);
}
Am I doing something wrong here?
I have been googling for an answer but could not find any.
My guess would be that the person experiencing the stackoverflow somehow starts the application with a lower maximum stack size.