Thread: Why isn't my game crashing??

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    Why isn't my game crashing??

    I'm new to DirectDraw, sorry if I don't make much sense..

    I'm using DirectDraw for the graphics (6.1. It's the only version I
    have on disk...)

    Anyway, I have a double buffer with (640*480) bytes allocated
    to it. I draw to this buffer, then copy that buffer to the primary
    surface...(of course...)

    I haven't put in any clipping or anything yet, so I don't know why
    this is happening; but when I move my character off the screen,
    he wraps around to the other side. The only function I have that
    deals with movement is a simple, temporary statement that says
    this:

    cEthic.SetX(cEthic.GetX()+5)

    It just keeps adding to cEthic's xPosition.

    What the freak is happening? I'm not writing directly to this memory,
    I'm writing to my buffer. Shouldn't my program crash after I've
    written to memory that wasn't allocated? I have no idea why it's
    wrapping around. It makes no sense! The xPosition of cEthic just
    keeps getting bigger and bigger. How can cEthic be drawn at
    a low xPosition when his xPosition should be greater than 700?

    If cEthic's xPosition is 635, then the image should extend beyond
    the 640 width limit of my buffer (and be drawn at (635, y)), not
    be wrapped around to (0, y)...



    I've attached a picture that shows what's happening...

    Thanks,

    ethic.
    Staying away from General.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    DDraw is most likely wrapping it for you. Once you implement clipping, it will probably go away, but we can't tell without code.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    Originally posted by XSquared
    DDraw is most likely wrapping it for you. Once you implement clipping, it will probably go away, but we can't tell without code.
    I thought not, but I don't know what code to post.

    Code:
    unsigned char* DoubleBuffer = new unsigned char [(640*480)];
    
    //...draw to da' buff...
    
    void Picture::dDrawThisPicture(unsigned char* buf, int x, int y)
    {
         int x = 0;
         for(int i = 0; i<PictureHeight; i++)
         {
              for(int j = 0; j<PictureWidth; j++)
              {
                    buf[((x+i) + (j*bufferwidth))] = PictureData[x++];
               }
          }
    }
    
    //...copy da' buff to da primary surf'
    
    void CopyBlahBlah(IDirectDrawSurface4*& ddsur)
    {
         //...
         else
         {
              for(int i = 0; i<height; i++)
              {
                   for(int j = 0; j<width; j++)
                        videomemory[(j+(i*memorypitch))] = DoubleBuffer[j+(i*width)];
              }
         }
    }
    It's pretty much like that (I think..), except everything is really
    part of a different class...
    Staying away from General.

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    That behaviour is expected. Remember that the video buffer is continuous (at least in your case)

    Directly after (639, y) comes (0, y+1)

    Got it?

    The guy on the other side is one pixel lower than the original guy.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Originally posted by Sang-drax
    That behaviour is expected. Remember that the video buffer is continuous (at least in your case)

    Directly after (639, y) comes (0, y+1)

    Got it?

    The guy on the other side is one pixel lower than the original guy.
    There was a huge post on the old board about that, but it got deleted.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Its MUCH faster to use BitBlt/BitBltFast instead of writing your own drawing function. For instance, DirectX might decide to let your video card do the drawing, improving speed. You can't do that from your function.

  7. #7
    monotonously living Dissata's Avatar
    Join Date
    Aug 2001
    Posts
    341
    leave it up to ethic to complain about something NOT crashing.
    if a contradiction was contradicted would that contradition contradict the origional crontradiction?

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Unexpected behaviour is bad. Therefore, not crashing is bad in this instance
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    73
    Originally posted by Sang-drax
    The guy on the other side is one pixel lower than the original guy.
    So, what happens after the yPosition is off the lower part of the screen? Will that crash it? or will it wrap up again to the top?

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Originally posted by Nuke
    So, what happens after the yPosition is off the lower part of the screen? Will that crash it? or will it wrap up again to the top?
    Most of the time it'll give you a "memory not accessible"/"invalid memory location" error.

  11. #11
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    Why isn't my game crashing??
    because you did something right.
    My Website

    "Circular logic is good because it is."

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-08-2010, 12:08 AM
  2. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. C++ Game of Life Program
    By rayrayj52 in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 03:58 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM