Skip to main content
GameDev.net gamedev.net
🔒 Locked

Blit fails sometimes, why?

Started by Sand_Hawk May 29, 2002 at 8:54 AM 0 replies 150+ views
Original Post
Sand_Hawk
Sand_Hawk
I have some test code ripped from TOTWGPG. It''s just an test to get to know DirectDraw. But sometimes my code fails to blit. This is my code:
  
    DDRAW_INIT_STRUCT(ddbltfx);
    ddbltfx.dwFillColor = _RGB16BIT565(rand()%256, rand()%256, rand()%256);
    int X1 = rand()%SCREENWIDTH ;
    int Y1 = rand()%SCREENHEIGHT;
    int X2 = rand()%SCREENWIDTH;
    int Y2 = rand()%SCREENHEIGHT;

    
    if (Y1 >= Y2)
    {
        int Temp = Y1;
        Y1 = Y2 + 1;
        Y2 = Temp;
    }

    if (X1 >= X2)
    {
        int Temp = X1;
        X1 = X2 + 1;
        X2 = Temp;
    }
    
    DestRect.left = X1;
    DestRect.top = Y1;
    DestRect.right = X2;
    DestRect.bottom = Y2;

    if (FAILED(lpddsPrimary->Blt(&DestRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx)))
        Log.Write("Failed to blit");
  
Anyone knows why it sometimes goed wrong? Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
----------------(Inspired by Pouya)
Michalson
Michalson
Since they are randomly assigned what if both X1 and X2 where both set to SCREENWIDTH-1 (the far right of the screen). When "if (X1 >= X2)" is run X1 will be set to X1+1, which is outside the bounds of the screen (invalid coordinates). Just a guess.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.