Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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 1055 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Kernel

Medals: 95
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.:

private static void writeFile(FileHandle fileHandle, Object object) throws Exception {
      ObjectOutputStream out = new ObjectOutputStream(fileHandle.write(false));

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:

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)
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: 95
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: 95
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.

Riven (32 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (27 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39

Jesse (40 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!