Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] Serializing save game data causes StackOverflow on Android  (Read 761 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Posted 2013-08-06 13:25:46 »

Hi all, I'm currently working the save game feature on a 2D space RTS game for desktop and Android systems. However, I'm having a hard time finding an approach that works well on Android.

The game state is contained in a single object ("galaxy" of class Galaxy). I write the galaxy object to a file using serialization. For this I both tried vanilla Java serialization and by using the Kryo library. The serialization code is pretty simple and standard, e.g.:

1  
2  
3  
4  
5  
private static void writeFile(FileHandle fileHandle, Object object) throws Exception {
      ObjectOutputStream out = new ObjectOutputStream(fileHandle.write(false));
      out.writeObject(object);
      out.close();
}


This is all very elegant and works fast & smooth as butter on my desktop computer. However, testing this on my Galaxy S2 Android smartphone results consistently in a StackOverflow exception Angry

I kind of know what is causing this: the stack size on Android is smaller than on my desktop computer. Also, the galaxy state object is somewhat nested, e,.g. something like:
1  
Galaxy.stars.get(0).fleets.get(0).get(0).velocity.x

Is a valid call (though somewhat silly) in my code base. However, the save game on my desktop is quite small (beteen 30k and 500k), so its not really a huge amount of data to handle.

There must be a better way to go at this. Do you guys have any ideas on how I could implement a save game feature which does not have this issue? Thanks.

Offline Jeremy
« Reply #1 - Posted 2013-08-06 14:30:12 »

Have you tried serializing in parts? I.e, serialize the first x stars, than save that. Then serialize the next x stars? It makes the process more complex because you would need to partition the list into different objects and append them into a single object for the game later - but you can probably achieve this.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline Herjan
« Reply #2 - Posted 2013-08-06 14:59:27 »

Wow, 500kb? That's A LOT of data, I don't know what your game is like, but I think if you make that class a bit more 'datafriendly' I mean if you save a unit: type, x-position, y-position, xvelo, yvelo, targetx, targety, and bought upgrades, '001 and 002'. That is (average) 30-50??? bytes per unit, save also some money and some buildings, and game saved (not even close). You must have a lot of space ships (or money, heheh) to get 500.000 bytes.

However this is useful or not (its not), good luck Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #3 - Posted 2013-08-06 15:53:37 »

@Herjan: Haha, you are right about the LOT of data. I accidently saved a helper array for each star (containing ordered distances to other stars, to speed up calculations). Without these helper arrays the data is reduced to below 50k (with hundreds of stars & ships). Thanks for the hint  Grin

@Jeremy: Sounds like something worth a try. I think I can figure out how to make that work.

Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #4 - Posted 2013-08-06 16:19:03 »

@Jeremy: I partitioned the save and load process and now it works like a charm! Thanks for the advice  Grin

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (69 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (82 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!