Tuesday, January 26, 2016

Disposing

Making a death screen huh?

Yep, hoping this one will be pretty fast.  Our prototype will have ugly barebones screens that may need to be refactored later.  Perhaps even the death screen should just be the new game screen.  Yeah.. Okay so let's just dispose of everything, load the new game screen, and reload the game.  (For now)

Great, what needs to be disposed of?

According to this list: https://github.com/libgdx/libgdx/wiki/Memory-management  At least a lot of stuff.  So let's call that dispose() method and figure out how to find memory leaks with the debugger.

if (hud.bar.getValue() == 80) {

    game.setScreen(new TransitionScreen(game));
    this.dispose();
}

Let's die at 80% health to speed this up.  Our first error is..!?  Crash to desktop!  Congratulations!

1) "Process finished with exit code -1073741571 (0xC00000FD)"

This seems like a great time to learn how to use a debugger, let's give it a whirl, setting a breakpoint at this.dispose().

Ahh, the culprit was calling world.dispose() two times.  Once in our playscreen dispose() and once in the Bottle class dispose().

2) AL lib: (EE) alc_cleanup: 1 device not closed

This happens because after we dispose of stuff our render method is still being called.. had to add a little 'disposed = true' check in the playscreen render().
update(delta);
if (disposed == true){
    break;
}

3) Couldn't load file: Spritesheets/explode2.png

Which was fixed by disposing an atlas in the bottle class.

4) Memory leak crash


Each spike set represents starting a new game and the plateau is the 'new game' screen after we die.
Well.. I guess it's a memory leak.. it doesn't seem like very much memory is being used, definitely something isn't being disposed but it crashes before it gets very high.. debug time!


Any progress?

This blog has an amazing post about how to hunt for memory leaks: 

I've got the programs it lists and I'm fired up! Let's dive into the matrix and be the Neo!







What is this?

Here we tried running the game three times, so we can see three big PlayScreen objects and their.. timers.  The timer class is.. big.  Like opening the bathroom door and finding your dog sitting on your toilet reading a newspaper.  It's just confusing.  A dog?  A timer?  What?    

I didn't even know I had a timer in PlayScreen.  And why only that timer?  There are a bunch of timers kicking around doing useful things.  

Upon closer inspection.. it's our beautiful nested timer.  The same one we made last week for the background animation.


*1 day later*

Whoa what happened?

Man.. I'll tell you what happened.  Disposing.  That's what happened.  The silly utterly naive me of last week went around adding resources willy nilly.  Drop a new local texture here, plant a new pixmap there.  So careless.  YOU WERE SO CARELESS! DO YOU HEAR ME??  I can't talk to my past self but I can talk to my future self.  Don't worry buddy, I got your back.  No more carelessness.  I promise.  You are looking at a changed man.  

It's fitting that I almost didn't even think this blog post would have any experiences worth recording.  "Don't even need a death screen.  Just dispose and make a new playscreen. That isn't even a paragraph."  I was happy for about 30 minutes when there was something interesting happening.  And then for 10 hours, I was less happy and more determined, and also somewhat confused and hesitant, like a mouse approaching a cheese.  Fully engaged, but man.  I was on the brink of getting down to that big rewrite which is inevitably coming.  All for want of a new playscreen.

Good job.  How do you feel after fixing all that?

A little burned out.  There's so much moving stuff happening in my life, about to head out to a new country (UAE) and be with my lady.  I want to just focus on making the game but there are furniture removers to call, friends to meet, classes to have, cleaning and throwing stuff away.  It's really not that much work I guess.  Just mentally taxing.  Very happy to get rid of the useless junk I've collected.    



Let's see if we can somehow stay productive throughout the move.  And also let's see if we can avoid being stressed out if we aren't all that productive.  Gotta enjoy the inconveniences too!

Still hoping to get a prototype out before the end of the week!


No comments:

Post a Comment