|
Game freezes after so many events happen why might this be? |
Antone333
Member #15,545
March 2014
|
so when playing the game i am working on it runs smoothly and the player can move the character as supposed to but every time after a certain number of movements the game freezes. i have recorded a couple of numbers: after these number of arrow key presses for the player movement the game freezes and in most cases the player tile map screen is erased leaving only the background tile map displayed on the screen. anyone have any ideas? the entire game is posted above. |
Chris Katko
Member #1,881
January 2002
|
Have you tried running it in a debugger and seeing if it throws a violation of some kind? If something blows up or crashes over time, it's basically going to be related to pointers, or some other memory violation like constantly creating data but never releasing it. The big things to look for are where ever pointers are changing, and whenever you are creating, and deleting data. If you're creating data, but not deleting it in the proper, same scope, things blow up. Does the RAM usage increase? You're running everything as global variables. One of the main reasons people use encapsulation is to prevent the amount of others things a particular "thing" can access. Why? Because it cuts the possible places for something to blow up. It rules things out. With everything global as it is, the problem could almost be anywhere. Your pages of hardcoded map data scare the hell out of me, to be honest. Those memcpy's at the end of each are definitely strange to my eyes. And you want functions to implement code that is "the same" over and over in those KEY cases, because otherwise if you change it in one place, you might forget an X or an X2, be off by one letter, and cause problems. Now, don't take that as harsh criticism. You're learning and that's fine. [edit] void PlayerMovement() { ALLEGRO_BITMAP *TaskMenu = NULL; TaskMenu = al_load_bitmap("TaskMenu.png"); You creating a new bitmap by reading from a file every time you call this function. That's slow at best, and as you can see later, you never destroy that bitmap at the end of the function, so you're rapidly creating new memory holes every single time. -----sig: |
Antone333
Member #15,545
March 2014
|
Hey Chris thanks a bunch for all the information. the problem i was having was solved by removing this: void PlayerMovement() that was left over from previously when i was trying to get the Menu working and i forgot to remove it. and i know that all of the maps are hard to look at. but i have been using tiled (map file above) and it gives me the integers for the maps and i just copy and paste from there into the program. so its not exactly hand coded in the sort of way where i would be writing them myself and having to remember all of the numbers and such. that would be impossible for me to work out. haha and i know that it would be a good idea to have functions for all the collision but im not really sure how i would put that in. perhaps make a function like this? that would work. right? i never thought about doing that but it would make things super simple. Thank you so much again for all of the help! / Oh and also, i am not really sure how exactly to use debugger on dev c++ i will look into it though. pretty much the same for all ide's? would you know anywhere i could go to look into that? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
For one thing you don't want to flip the display every time you get an event. You want to process all the events at once and then redraw when the queue is empty. Try fixing that first. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Mishtiff
Member #15,776
October 2014
|
Hi Antone333, I have already been informed about this and figured i would pass on the information. You should never load bitmaps during gameplay, it should always happen prior to the gameloop. So, lets say you have a menu, a game, and a victory/defeat state. Each should load every bitmap prior to running and then destroy them after they have left to a new state. if(state == menu) after this, you would either return to the menu/game, or you would destroy all used bitmaps. Remember that if you are giving the ability to return to the menu or game, you will just need to destroy them at the end of the application (unless they are too large to keep in memory during the time in other states). To expand on what Edgar said: Flipping the display is like telling the backbuffer to be drawn to the screen. if you are constantly flipping it, you are wasting the built in doublebuffer! hope this helps! I have been trying to learn just like yourself |
pkrcel
Member #14,001
February 2012
|
Mishtiff said: You should never load bitmaps during gameplay This demands for a little nitpick. You absolutely CAN load bitmaps (textures) during gameplay, there would be cases in which you're SUPPOSED to do that, if you're efficiently managing your resources. What you should avoid is to do that regardless of the availability of said bitmap, or in other words continously load the same bitmap over and over when it's not needed cause it's already in (video)memory. It is unlikely that Google shares your distaste for capitalism. - Derezo |
Mishtiff
Member #15,776
October 2014
|
Thanks for keeping me in check |
|