BitBlt Error Trapping


Hey guys, been running a tile engine type game for a while now and going over it fixing some error trapping and doing some optimising. Wondering if you can help me out.

I havn't got any error trapping on the graphics ruitines, which are running through API's BitBlt. he problem is that sometimes grpahical elements dont load properly and i need to restart the program so that it loads. This can happen to one or more of the graphics on the game.

Anyone know any procedures to combat this problem?

Ms

Comments

  • :
    : Hey guys, been running a tile engine type game for a while now and going over it fixing some error trapping and doing some optimising. Wondering if you can help me out.
    :
    : I havn't got any error trapping on the graphics ruitines, which are running through API's BitBlt. he problem is that sometimes grpahical elements dont load properly and i need to restart the program so that it loads. This can happen to one or more of the graphics on the game.
    :
    : Anyone know any procedures to combat this problem?
    :
    : Ms
    :

    No one has ANY idea?
  • : :
    : : Hey guys, been running a tile engine type game for a while now and going over it fixing some error trapping and doing some optimising. Wondering if you can help me out.
    : :
    : : I havn't got any error trapping on the graphics ruitines, which are running through API's BitBlt. he problem is that sometimes grpahical elements dont load properly and i need to restart the program so that it loads. This can happen to one or more of the graphics on the game.
    : :
    : : Anyone know any procedures to combat this problem?
    : :
    : : Ms
    : :
    :
    : No one has ANY idea?
    :

    Well... You can put the AutoRedraw property of whatever control (or form) you are drawing on to True. Then run though the code using VB's Debugger. Using the AutoRedraw you can switch between your form and the debugger and still see the result. Without AutoRedraw, the draw operations will be lost, because it actually needs to redraw them, but since you're stopping the code with the debugger this won't work. The AutoRedraw will make sure any changes are 'saved' temporarily and redrawn when necessary.

    Greets...
    Richard

  • : Well... You can put the AutoRedraw property of whatever control (or form) you are drawing on to True. Then run though the code using VB's Debugger. Using the AutoRedraw you can switch between your form and the debugger and still see the result. Without AutoRedraw, the draw operations will be lost, because it actually needs to redraw them, but since you're stopping the code with the debugger this won't work. The AutoRedraw will make sure any changes are 'saved' temporarily and redrawn when necessary.
    :
    : Greets...
    : Richard

    Thanks Richard but AutoRedraw is already set. It looks like its a problem with loading the bitmap (maybe GenerateDC) but I still dont know how to error trap it.
    Ross

  • : : Well... You can put the AutoRedraw property of whatever control (or form) you are drawing on to True. Then run though the code using VB's Debugger. Using the AutoRedraw you can switch between your form and the debugger and still see the result. Without AutoRedraw, the draw operations will be lost, because it actually needs to redraw them, but since you're stopping the code with the debugger this won't work. The AutoRedraw will make sure any changes are 'saved' temporarily and redrawn when necessary.
    : :
    : : Greets...
    : : Richard
    :
    : Thanks Richard but AutoRedraw is already set. It looks like its a problem with loading the bitmap (maybe GenerateDC) but I still dont know how to error trap it.
    : Ross
    :
    :

    You can only trap errors between calls. There is no way to debug an API function. Probably, there is something wrong with your call

    Greets...
    Richard

  • :
    : You can only trap errors between calls. There is no way to debug an API function. Probably, there is something wrong with your call
    :
    : Greets...
    : Richard
    :

    I suspect it's my GenerateDC function. Is there no way to check to see if it has loaded correctly?

    My Code:

    Public Function GenerateDC(FileName As String) As Long
    'IN: FileName: The file name of the graphics
    'OUT: The Generated DC

    Dim DC As Long
    Dim hBitmap As Long

    'Create a Device Context, compatible with the screen
    DC = CreateCompatibleDC(0)

    If DC < 1 Then
    GenerateDC = 0
    Exit Function
    End If

    'Load the image....BIG NOTE: This function is not supported under NT, there you can not
    'specify the LR_LOADFROMFILE flag
    hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)

    If hBitmap = 0 Then 'Failure in loading bitmap
    DeleteDC DC
    GenerateDC = 0
    Exit Function
    End If

    'Throw the Bitmap into the Device Context
    SelectObject DC, hBitmap

    'Return the device context
    GenerateDC = DC

    'Delte the bitmap handle object
    DeleteObject hBitmap

    End Function 'GenerateDC
  • : :
    : : You can only trap errors between calls. There is no way to debug an API function. Probably, there is something wrong with your call
    : :
    : : Greets...
    : : Richard
    : :
    :
    : I suspect it's my GenerateDC function. Is there no way to check to see if it has loaded correctly?
    :
    : My Code:
    :
    : Public Function GenerateDC(FileName As String) As Long
    : 'IN: FileName: The file name of the graphics
    : 'OUT: The Generated DC
    :
    : Dim DC As Long
    : Dim hBitmap As Long
    :
    : 'Create a Device Context, compatible with the screen
    : DC = CreateCompatibleDC(0)
    :
    : If DC < 1 Then
    : GenerateDC = 0
    : Exit Function
    : End If
    :
    : 'Load the image....BIG NOTE: This function is not supported under NT, there you can not
    : 'specify the LR_LOADFROMFILE flag
    : hBitmap = LoadImage([red]App.hInstance[/red], FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    :
    : If hBitmap = 0 Then 'Failure in loading bitmap
    : DeleteDC DC
    : GenerateDC = 0
    : Exit Function
    : End If
    :
    : 'Throw the Bitmap into the Device Context
    : SelectObject DC, hBitmap
    :
    : 'Return the device context
    : GenerateDC = DC
    :
    : 'Delte the bitmap handle object
    : DeleteObject hBitmap
    :
    : End Function 'GenerateDC

    I made one modification in your code (red). I don't know if it matters any bit, but it could be the problem.

    I am not sure about the "DeleteObject hBitmap" line at the end. Won't it remove the bitmap from memory before it can be drawn? I'm not really good at API drawing, so I can't be sure.

    Greets...
    Richard

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories