Author Topic: Debugging, how to?  (Read 1584 times)

Offline r0ber7

  • Prof. Inline
  • *****
  • Posts: 525
    • View Profile
Debugging, how to?
« on: 2015-Jan-08 »
Alright. I have this huge project of a game I'm working on, you may remember it. ;-)

So I know that somewhere along the line during the playing of a level, things get slowed down. If I leave a level playing for 15 minutes I see a drop in framerate. This leads me to conclude that somewhere, an array is not being cleaned up, or what I don't know.

All I know is, the memory usage grows and grows. In GLBasic IDE, how would I go about debugging this? I have never really used the debugging tools, only the DEBUG command. What is this continue, next step, etc. about? Can it help me find out what is causing the memory growth?

I'm on a gigantic bug hunt which started a month ago. Any help will be greatly appreciated. :)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1766
    • View Profile
    • Homepage
Re: Debugging, how to?
« Reply #1 on: 2015-Jan-08 »
The simplest thing you can do if you have performance problems is to activate the profiler. This tells you where your program spends most time.

Compiler->Profiler->Activate
Run your game until you get the slowdown. Exit game.
Compiler->Profiler->Output
This opens the profiler output file in the editor. MAKE SURE YOU CLOSE THIS WINDOW when you are done with it, it can cause loading problems in certain situations. You will have to do some hacking to be able to load your project again.

Now when you know what routine is slowing you down, go there in the editor. Here you can set a break point by setting cursor on a line with a command on it (not comment, has to be a command) and press F9. Make sure the debug mode is on and run the game. It will stop on this line. Now you can slowly step through your program with the CTRL or SHIFT+F10 button.
"Step out" will run everything on the line, even function/subroutines and continue on the next line. This so you don't have to go through a whole tree of subroutines if you don't want to.

You also get all the variables loaded by your application and can see the content of them in the right (debug) window.
Try also to point your mouse-cursor on commands and variables in your source code, this should also work to give you the content or short help about commands and variables.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4142
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Debugging, how to?
« Reply #2 on: 2015-Jan-08 »
I bet what's happening is you aren't deleting sprite TYPE(s) properly (or an array as you've already suggested) and they are increasing in number and getting repeatedly drawn (or not if off-screen, but being iterated anyway). Make sure that you delete every sprite once it's no longer needed and that after each game you delete them all too.

That would be my guess, as I've had this before.
I came. I saw. I played.

Offline r0ber7

  • Prof. Inline
  • *****
  • Posts: 525
    • View Profile
Re: Debugging, how to?
« Reply #3 on: 2015-Jan-08 »
The simplest thing you can do if you have performance problems is to activate the profiler. This tells you where your program spends most time.

Thank you very much for this detailed explanation, this helps me a lot!  :D

Ian: yep, probably. The problem is, I have several layers of abstraction, and many different arrays for different game objects. So I think you're right, but the question remains, where -in that giant heap of code- is it happening? :P

But now I am armed with new knowledge and will surely find the bug!  :good:

Offline hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 489
    • View Profile
Re: Debugging, how to?
« Reply #4 on: 2015-Jan-12 »
The simplest thing you can do if you have performance problems is to activate the profiler. This tells you where your program spends most time.

Compiler->Profiler->Activate
Run your game until you get the slowdown. Exit game.
Compiler->Profiler->Output
This opens the profiler output file in the editor. MAKE SURE YOU CLOSE THIS WINDOW when you are done with it, it can cause loading problems in certain situations. You will have to do some hacking to be able to load your project again.

Thanks, I didn't know this profiler option in GLB. I mark this thread to test later.