Help....with freezing game

This is a discussion on Help....with freezing game within the Game Programming forums, part of the General Programming Boards category; well when i compile my game i get a weird freezing error when i start the exe file...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    Help....with freezing game

    well when i compile my game i get a weird freezing error when i start the exe file
    Attached Files Attached Files

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Try a warmer room.

    In all seriousness just posting a problem with tons of source is a bit lazy. What are the errors?
    Any compiler warnings? When does it crash?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Learn how to use a debugger.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    it crashes my computer xD, yet i try some debugging crashes agian

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Quote Originally Posted by Darkinyuasha1 View Post
    it crashes my computer xD, yet i try some debugging crashes agian
    Yeah, well... a debugger isn't going to stop it from crashing, it will however give you some nifty information about what's happening as it's crashing. As Salem said, learn how to use a debugger or perhaps use a better debugger.
    Last edited by SlyMaelstrom; 08-18-2007 at 10:10 PM.
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Also sounds like a case of programming it completely before any kind of testing has been done. Basicly in the future you want to add small(ish) pieces of code and then run tests on the program, just so you can spot problem-areas when things crashes. This will help you debug these types of problems.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    well i have been debugging it, and i still get a case of a freezing screen as the output i do suspect it's from my GameInit() function thou

    Code:
    void GameInit()
    {
    
     HDC hdcc =GetDC(ghWnd);
    SetRect(&rtemp,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE);
     AdjustWindowRect(&rtemp,WS_CAPTION|WS_VISIBLE|WS_SYSMENU,false);
     SetWindowPos(ghWnd,NULL,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,SWP_NOMOVE); 
     
     MapImage.CreateImage(hdcc,"gamescreen.bmp");
     BarImage.CreateImage(NULL,"Bar.bmp");
     BallImage.CreateImage(NULL,"ball.bmp");
     Paddle.CreateImage(NULL,"Paddle.bmp");
     
     NewGame();
     
    }
    
    void NewGame()
    {
     GAMESTARTED = false;
     
     for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
     for(int ymi = 0; ymi < 60; ++ymi)
    {
     if(ymi < 10)
     MAP[xmi][ymi] = REDBAR;
     else
     MAP[xmi][ymi] = BLACKBAR;
     
     DrawBars(xmi,ymi,MAP[xmi][ymi]);
    }
     
     ball.Startpos( SCREEN_WIDTH / 2, 120  );
     PaddleInit();
     
     UpDateGame();
     
    }
    
    void UpDateGame()
    { 
     
     if( GAMESTARTED == true)
    {
     collision();
     PREBALL_X = BALL_X;
     
     PREBALL_Y = BALL_Y;
     
     BALL_X    = ball.GetX_val();
    
     BALL_Y    = ball.GetY_val();
     
     ball.Move();
     
     DrawPaddle(Paddle_X, Paddle_Y);
     UpdateWindow(ghWnd);
     ShowWindow(ghWnd,SW_SHOW);
     
    }
    
     InvalidateRect(ghWnd,NULL,false); 
    }
    im still a bit new to windows soo i wish for some help and advice on how to fix this bug.....

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You call GetDC, but do you call ReleaseDC anywhere?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    ooh well thanks for that point

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    when i used breakspoint it stop at DrawBars() function, so that might be an error somewhere in there too...
    Code:
    void NewGame()
    {
     GAMESTARTED = false;
     
     for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
     for(int ymi = 0; ymi < 60; ++ymi)
    {
     if(ymi < 10)
     MAP[xmi][ymi] = REDBAR;
     else
     MAP[xmi][ymi] = BLACKBAR;
     
     DrawBars(xmi,ymi,MAP[xmi][ymi]);
    }
      void DrawPaddle(int _X, int _Y)
    {    //checks to see if there was any previous ball movement
         if(Paddle_Move == true)
     BitBlt(MapImage,PrePaddle_X,PrePaddle_Y,8,1,Paddle,0,1,SRCCOPY);
         //updates iamge
     BitBlt(MapImage,_X,_Y,8,1,Paddle,0,0,SRCCOPY);
     
    };
    the whole main code is this

    Code:
    #include "ball.h"
    #include "ImageClass.h"
    #include<windows.h>
    
    //size of bars
    #define BAR_SIZE 8
    
    #define SCREEN_WIDTH 20
    
    #define SCREEN_HEIGHT 30
    //color bars
    #define REDBAR 1
    //to erase bars
    #define BLACKBAR 0
    
    //map array fir bars to be place in
    int MAP[SCREEN_WIDTH ][SCREEN_HEIGHT];
    // value ot use when to check the game is finish
    bool GAMESTARTED;
    // check if paddle is moving
    bool Paddle_Move = false;
    //gets time in milli seconds
    // Started time
    DWORD timerstart;
    // difference of  start and current time
    DWORD timercurrent;
    //images for each visible component
    //ball
    ImageClass BallImage;
    //map
    ImageClass MapImage;
    //bars 
    ImageClass BarImage;
    //paddle
    ImageClass Paddle;
    //global handle
    HWND ghWnd;
    
    // a class to calculate ball's movements
    BallClass ball;
    //current ball's coordiantes
    int BALL_X;
    
    int BALL_Y;
    //preious coordinates
    int PREBALL_X;
    
    int PREBALL_Y;
    //current paddle coordinates
    int Paddle_X =0;
    
    int Paddle_Y =0;
    // previous paddle coordinates
    int PrePaddle_X;
    
    int PrePaddle_Y;
    //sets the new game
    void NewGame();
    // draws bar image
    void DrawBars(int x, int y, int title);
    // checks for bar and  ball collision (still working on it )
    void collision();
    // draw paddle image 
    void DrawPaddle( int _X, int  _Y);
    // init paddle
    void PaddleInit();
    // game loop
    void UpDateGame();
    // game init
    void GameInit();
    
    LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {// gets speed desired by the user
     int N = 0;
     
     switch( uMsg)
     {
      case WM_KEYDOWN:
    {       
           switch(wParam)
           {
            
            case VK_RETURN:
            GAMESTARTED = true;
            break;
            // moves paddle right
            case  VK_RIGHT:
            Paddle_X -= 8;
            Paddle_Move = true;
            break;
            //moves paddle left
            case  VK_LEFT:
            Paddle_X += 8;
            Paddle_Move = true;
            break;
           //increases ball speed 
            case  VK_UP:
            N += 1;
            ball.Speed(N);
            break;
            //decreases ball speed
            case  VK_DOWN:
            N -= 1;
            break;
           }
    }
     //copys entire buffer onto the main client's
     case  WM_PAINT:
    { 
     PAINTSTRUCT ps;
     HDC hdc = BeginPaint(ghWnd,&ps);
     
     BitBlt(hdc,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,MapImage,0,0,SRCCOPY);
     
                EndPaint(ghWnd,&ps);
     return (0);
    } 
     break;
     
     case   WM_DESTROY:
    {
     PostQuitMessage(0);
     
     return(0);
     
    } 
     break;
     
     default :
      return (DefWindowProc(hwnd,uMsg,wParam,lParam));     
    
     }
    
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
     timerstart = GetTickCount();
     
     WNDCLASSEX wc;
    
     wc.cbSize = sizeof(WNDCLASSEX);
     wc.style  = CS_VREDRAW|CS_HREDRAW;
     wc.lpfnWndProc = (WNDPROC)WindowProc;
     wc.cbClsExtra  = 0;
     wc.cbWndExtra  = 0;
     wc.hInstance   = hInstance;
     wc.hIcon       =LoadIcon(NULL,IDI_APPLICATION);
     wc.hCursor     = LoadCursor(NULL,IDC_ARROW);
     wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
     wc.lpszMenuName  = NULL;
     wc.lpszClassName = "Blizt game";
     wc.hIconSm       = NULL;
     
     RegisterClassEx(&wc);
     
     ghWnd = CreateWindowEx(WS_EX_WINDOWEDGE,"Blizt game","Demo game",WS_SYSMENU|WS_CAPTION |WS_BORDER,0,0,160,240,NULL,NULL,hInstance,NULL);
     
     GameInit();
     
     MSG msg;
     
     for( ; ; )
     {// updates every second
         timercurrent = GetTickCount() - timerstart;
      if(timercurrent > 1000.0)
      {  UpDateGame();
         timerstart = timercurrent;
      } //checks for quit 
      if(PeekMessage(&msg,ghWnd,0,0,PM_REMOVE))
     { if(msg.message == WM_QUIT) break;
      
      TranslateMessage(&msg);
      
      DispatchMessage(&msg);
     }
     }
      
     
     return msg.wParam;
     
    } 
     
    
    void DrawBars(int x, int y, int title)
    {
     BitBlt(MapImage,x* BAR_SIZE,y* BAR_SIZE,BAR_SIZE,BAR_SIZE,BarImage,title * BAR_SIZE, title * BAR_SIZE,SRCAND );
     
     BitBlt(MapImage,x* BAR_SIZE,y* BAR_SIZE,BAR_SIZE,BAR_SIZE,BarImage,title * BAR_SIZE, title * BAR_SIZE + BAR_SIZE,SRCPAINT );
    }
    
    void PaddleInit()
    {
     Paddle_X = 8;
     
     Paddle_Y = 208;
    
     DrawPaddle( Paddle_X, Paddle_Y);
    
    
    }
    
    void DrawPaddle(int _X, int _Y)
    {    //checks to see if there was any previous ball movement
         if(Paddle_Move == true)
     BitBlt(MapImage,PrePaddle_X,PrePaddle_Y,8,1,Paddle,0,1,SRCCOPY);
         //updates iamge
     BitBlt(MapImage,_X,_Y,8,1,Paddle,0,0,SRCCOPY);
     
    };
    
    //erases previous image then makes new iamge movement for ball(also paddle)
    void DrawBall()
    {
     if(GAMESTARTED == true)
     BitBlt(BallImage,PREBALL_X,PREBALL_Y,8,8,BallImage,2 * 8, 0, SRCCOPY);
     
     BitBlt(BallImage,BALL_X,BALL_Y,8,8,BallImage,0,0,SRCAND);
     
     BitBlt(BallImage,BALL_X,BALL_Y,8,8,BallImage,2 * 8, 2*8, SRCPAINT);
     
    }
    
    
    void collision()
    {
     if(Paddle_X > SCREEN_WIDTH)
        Paddle_X -= 1;
        
      if(Paddle_X < 0)
        Paddle_X += 1;
     
     if(ball.GetX_val() > SCREEN_WIDTH)
        ball. Newdirection( 8,0);
     
      if(ball.GetY_val() < 0 )
        ball.Newdirection(0,-8);
     
     if(ball.GetY_val() == 206)
     /*    end of round          */
     
     if (ball.GetY_val()== Paddle_X - 1)
     ball.Newdirection(8,0);
     
    }
     
     
     
        
    
    void UpDateGame()
    { 
     
     if( GAMESTARTED == true)
    {
     collision();
     PREBALL_X = BALL_X;
     
     PREBALL_Y = BALL_Y;
     
     BALL_X    = ball.GetX_val();
    
     BALL_Y    = ball.GetY_val();
     
     ball.Move();
     
     DrawPaddle(Paddle_X, Paddle_Y);
     
     
    }
    
    InvalidateRect(ghWnd,NULL,false); 
    }
    
    void NewGame()
    {
     GAMESTARTED = false;
     
     for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
     for(int ymi = 0; ymi < 60; ++ymi)
    {
     if(ymi < 10)
     MAP[xmi][ymi] = REDBAR;
     else
     MAP[xmi][ymi] = BLACKBAR;
     
     DrawBars(xmi,ymi,MAP[xmi][ymi]);
    }
     
     ball.Startpos( SCREEN_WIDTH / 2, 120  );
     PaddleInit();
     
     UpDateGame();
     
    } 
    
    void GameInit()
    {
     RECT rtemp;
     HDC hdcc =GetDC(ghWnd);
     SetRect(&rtemp,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE);
     AdjustWindowRect(&rtemp,WS_CAPTION|WS_VISIBLE|WS_SYSMENU,false);
     SetWindowPos(ghWnd,NULL,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,SWP_NOMOVE); 
     
     MapImage.CreateImage(hdcc,"gamescreen.bmp");
     BarImage.CreateImage(NULL,"Bar.bmp");
     BallImage.CreateImage(NULL,"ball.bmp");
     Paddle.CreateImage(NULL,"Paddle.bmp");
     ReleaseDC(ghWnd,hdcc);
     NewGame();
     
    }

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ehm, if you use breakpoints, then I'd expect the debugger to stop there! That's the whole point of breakpoints.

    I would also like to echo the sentiments before of "posting huge bits of code with 'unknown' faults" is not a very productive way to solve problems. Try to isolate your problem to a few lines, then ask for help (but most likely, you'll find the problem yourself at that point).

    --
    Mats
    Last edited by matsp; 08-19-2007 at 06:22 PM.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    ^ thank you (scarcasm)

    >..> i just wanna know what happen too confuse

  13. #13
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    If you want help with this you would probably be best off creating a small test prog that reproduces the problem. It may take some, but by doing this I have often sorted out problems with my own progs. Seriously, you will be very lucky if you find anyone willing to go through a load of code for you trying to fix unknown problems.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    ooh thanks u mean like recreating what the program suppose to do at specific parts .....

  15. #15
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Yes, break it into pieces that can stand alone. Then you will know where your problem is assuming each of the pieces is just the same as it was in the whole program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21