Results 1 to 9 of 9

Thread: simpLe animation, hangs on unload ; * )

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    simpLe animation, hangs on unload ; * )

    Save a BMP (any, for a test, spIN.bmp) and run the code below. The animation plays but.. when you press the x (not stop in VB IDE). The animation does not close, it hangs still pLaying and your forced to end task.. but why~?

    VB Code:
    1. 'Sonikku`s cOde-_-
    2. Option Explicit
    3. Dim DX As New DirectX7
    4. Dim DD As DirectDraw7
    5. Dim ddsd1 As DDSURFACEDESC2
    6. Dim ddsd2 As DDSURFACEDESC2
    7. Dim Primary As DirectDrawSurface7
    8. Dim PiCBuFFeR As DirectDrawSurface7
    9. Dim bInit As Boolean
    10. Dim brunning As Boolean, brestore As Boolean
    11. Dim ddclipper As DirectDrawClipper
    12.  
    13. Private Type AnimationFrame
    14.     Top As Long
    15.     Left As Long
    16. End Type
    17. Dim Frame(4) As AnimationFrame
    18. Dim CurFrame As Integer
    19. Dim Dir_up As Boolean
    20. Dim LastTimeDrawn As Long
    21. Const Delaytime = 1000 / 25
    22.  
    23. Private Sub Form_load()
    24.     Init
    25. End Sub
    26.  
    27. Sub Init()
    28.     Set DD = DX.DirectDrawCreate("")
    29.     Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
    30.     ddsd1.lFlags = DDSD_CAPS
    31.     ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
    32.        
    33.     Set Primary = DD.CreateSurface(ddsd1)
    34.     ddsd2.lFlags = DDSD_CAPS
    35.     ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    36.        
    37.     Set PiCBuFFeR = DD.CreateSurfaceFromFile("SpIN.bmp", ddsd2)
    38.     CreateLookUpTable
    39.    
    40.     Set ddclipper = DD.CreateClipper(0)
    41.     ddclipper.SetHWnd picbox.hWnd
    42.     Primary.SetClipper ddclipper
    43.        
    44. bInit = True
    45. brunning = True
    46. bLt
    47. End Sub
    48.  
    49. Sub EndiT()
    50.     DD.RestoreDisplayMode
    51.     brunning = False
    52.     End
    53. End Sub
    54.  
    55. Private Sub Form_Resize()
    56.     picbox.Height = Me.ScaleHeight
    57.     picbox.Width = Me.ScaleWidth
    58.     Do While brunning = True
    59.         DoEvents
    60.         bLt
    61.         DoEvents
    62.     Loop
    63. End Sub
    64.  
    65. Sub bLt()
    66.     Dim ddrval As Long
    67.     Dim r1 As RECT
    68.     Dim r2 As RECT
    69.     Call DX.GetWindowRect(picbox.hWnd, r1)
    70.  
    71.     r2.Top = Frame(CurFrame).Top
    72.     r2.Left = Frame(CurFrame).Left
    73.     r2.Bottom = r2.Top + 31
    74.     r2.Right = r2.Left + 31
    75.    
    76.     If DX.TickCount >= LastTimeDrawn + Delaytime Then
    77.         LastTimeDrawn = DX.TickCount
    78.  
    79.         If Dir_up = True Then
    80.             CurFrame = CurFrame + 1
    81.             If CurFrame = 5 Then
    82.  
    83.                 CurFrame = 0
    84.                 Dir_up = True
    85.             End If
    86.         Else
    87.             CurFrame = CurFrame - 1
    88.             If CurFrame = -1 Then
    89.                 CurFrame = 0
    90.                 Dir_up = True
    91.             End If
    92.         End If
    93.     End If
    94.     DoEvents
    95.     ddrval = Primary.bLt(r1, PiCBuFFeR, r2, DDBLT_WAIT)
    96. End Sub
    97.  
    98. Sub CreateLookUpTable()
    99.     Frame(0).Top = 0: Frame(0).Left = 0
    100.     Frame(1).Top = 0: Frame(1).Left = 31
    101.     Frame(2).Top = 0: Frame(2).Left = 62
    102.     Frame(3).Top = 0: Frame(3).Left = 93
    103.     Frame(4).Top = 0: Frame(4).Left = 124
    104. End Sub
    105.  
    106. Private Sub Form_Unload(Cancel As Integer)
    107.     EndiT
    108. End Sub
    109.  
    110. Private Sub Picbox_Paint()
    111.     DD.RestoreAllSurfaces
    112.     Init
    113.     bLt
    114. End Sub
    Last edited by scr0p; Mar 6th, 2003 at 07:31 PM.
    asdf

  2. #2
    Addicted Member Sonikku`'s Avatar
    Join Date
    Oct 2002
    Location
    NyC~
    Posts
    165

    YeA~

    I thought Brunning = False wuld stop the loop and End the App. I was wrong, heres FiLE-
    Attached Files Attached Files

  3. #3
    New Member
    Join Date
    Dec 2002
    Posts
    11
    #1) Please don't post executables, how can we help you without the code? Even if the code was posted before, executables are likely not to be opened by any user because of trojans and other virus types of files.
    #2) This is very easy to fix, just add END after you set bRunning=false. Or it could be that you never terminated the surfaces, so try that too.

  4. #4
    Addicted Member Sonikku`'s Avatar
    Join Date
    Oct 2002
    Location
    NyC~
    Posts
    165

    Yea, dunno why

    Thats in the code I already have, when Event Query_unload occurs goto Sub EndiT(), There I tell it brunning = False which should stop the loop allowing it to END, but it doesnt!? WeirD~

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You know something's wrong with your code when you're spawning a new instance of DirectX with every paint event...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Addicted Member Sonikku`'s Avatar
    Join Date
    Oct 2002
    Location
    NyC~
    Posts
    165

    Smacks ForeHead

    OH~ It keeps repeating the Init sequence. I guess thats why its such a resource HoG.

  7. #7
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Originally posted by AtonalPanic
    #2) This is very easy to fix, just add END after you set bRunning=false. Or it could be that you never terminated the surfaces, so try that too.
    NEVER, repeat NEVER use the End statement to stop your program under normal conditions. Destroy all objects you've created and unload all forms.

  8. #8

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    but how`-`
    asdf

  9. #9
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    More than likely this is your problem:
    Code:
    Private Sub Picbox_Paint()
        DD.RestoreAllSurfaces
        Init
        bLt
    End Sub
    You shouldn't need any of this.

    Also, you should be able to replace the End statement with Unload Me.

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