Results 1 to 6 of 6

Thread: A difficult Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    Unhappy A difficult Question

    Here is something I've been struggling with for a long time.
    Below is the code that generates memory dc's (in type long variables) for a game I'm writting.

    For the most part I just hold the same dc's in memory once they are created so everything runs fast. But what I would like to be able to do is delete certain dc's, and then replace them with different pictures so like if you change clothes only one set of clothing dc's will be in memory at a time.

    Currently not only does putting a new dc into the long variable NOT save memory but it also compleatly screws up the the sprites ability to display correctly. Any help would be appreciated.

    Public Function GenerateDC(Sprite As String)
    Dim DC As Long, pictemp As IPictureDisp

    DC = CreateCompatibleDC(0)
    'If DC < 1 Then
    ' Exit Function
    'End If
    Set pictemp = LoadResPicture(Sprite, bitmap)
    SelectObject DC, pictemp
    DeleteObject pictemp
    Set pictemp = Nothing

    GenerateDC = DC
    End Function

    Private Sub createDCs()
    Stance1s = GenerateDC("STANCE1S")
    Stance2s = GenerateDC("STANCE2S")
    Stance3s = GenerateDC("STANCE3S")
    Stance1m = GenerateDC("STANCE1M")
    '---------many more of these...
    end sub
    All will fall before the might of the Black Sashi...

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC as Long) as Long

    Call this when you want to delete a DC.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    Question memory

    Well the whole point is to save memory. Simply deleting the old DC then setting a new value to it doesn't save anything it leaks memory somehow. In fact if I just added more dc's I'd be using the exact same amount of memory as deleting and replacing them, only I wouldn't have a leak. I'm starting to think that is the only solution.
    All will fall before the might of the Black Sashi...

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't think DeleteDC leaks anything.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    why don't you try it then?

    try it. If you loop the process around 1000 times or more depending on the size of the bitmap you are using you'll see that replacing dc's leaks memory if all you use is the deleteDC function.
    All will fall before the might of the Black Sashi...

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hum Fox had that problem a while ago, I'd help you but I never used BitBlt except for some early tests where I used pictureboxes and map editors. PM Fox about it
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width