20 May '13 - 17:49 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: BASS_CDG and VB.NET UserDraw - Memory issue  (Read 380 times)
VincentVega
Posts: 2


« on: 28 May '12 - 09:08 »
Reply with quoteQuote

Hello!

I have a big Problem with BASS_CDG. First of all everything works. But when I start the CDG Playback, the memory consumption rises from 18MB to over 400MB in small steps. I have found out that the Problem is in the Timer Event in this row:
bmptemp = BassCdg.BASS_CDG_GetCurrentBitmap(mMP3Stream)

Here is my Code:

BassInitialisation:
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)

StartPlayback:
Dim PlugIn As Integer = 0
        Dim PlugInFX As Integer = 0

        If mMP3Stream <> 0 Then Bass.BASS_StreamFree(mMP3Stream)
        PlugIn = Un4seen.Bass.Bass.BASS_PluginLoad("bass_cdg.dll")

        'set this to enable user drawing
        BassCdg.BASS_CDG_SetConfig(Un4seen.Bass.AddOn.Cdg.BASSCDGConfig.BASS_CDG_USERDRAW, 1)
       
        If PlugIn <> 0 Then
            ' Create the CDG Stream
            mMP3Stream = Bass.BASS_StreamCreateFile(tbFileName.Text, 0, 0, BASSFlag.BASS_UNICODE)

            'Make mCDGForm -> A Form to Display the CDG
            ShowCDGForm()

            'and finally play the stream
            Bass.BASS_ChannelPlay(mMP3Stream, False)

            '!!! Start the Timer to Display the Bitmaps in UserDrawMode           
            Timer1.Enabled = True
        End If

...and here the TimerCode:
If mMP3Stream <> 0 Then
            Dim bmptemp As IntPtr
            Dim bmpdb As Bitmap

            'Bild in Bitmap umwandeln und vertikal spiegeln
            bmptemp = BassCdg.BASS_CDG_GetCurrentBitmap(mMP3Stream)
            bmpdb = System.Drawing.Image.FromHbitmap(bmptemp)

            bmpdb = System.Drawing.Image.FromHbitmap(BassCdg.BASS_CDG_GetCurrentBitmap(mMP3Stream))
            bmpdb.RotateFlip(RotateFlipType.RotateNoneFlipY)
         
            PictureBox1.Image = bmpdb
            mCDGFormPic.Image = bmpdb


            'Free
            bmpdb = Nothing
            bmptemp = Nothing
        End If

I have no Idea what I can do now. The Problem exists in 64 and x86 Mode. The memory rises even if I shrink the Timer-Code to the problem row "BASS_CDG_GetCurrentBitmap". When I delete this row I have no memory problems.

Please help..

Vinvent Vega
Logged
Ionut Cristea
Posts: 1373


« Reply #1 on: 28 May '12 - 14:53 »
Reply with quoteQuote

  Maybe you should use DeleteObject function to delete the HBITMAP
Logged
VincentVega
Posts: 2


« Reply #2 on: 28 May '12 - 21:34 »
Reply with quoteQuote

Ionut you're a Genius!

I solved the Problem by using this Code:
<DllImport("gdi32.dll", EntryPoint:="DeleteObject")> _
    Private Shared Function DeleteObject(ByVal hObject As IntPtr) As Integer
    End Function

...and in the Timer Sub:
...
bmpdb = System.Drawing.Image.FromHbitmap(bmptemp)

'Drop the IntPtr Object
DeleteObject(bmptemp)
...

But a question to all VB.Net Users out there... is it really necessary to import the gdi32.dll only to Delete the Object?

Thanks for solving my problem Ionut.

VincentVega
Logged
Ionut Cristea
Posts: 1373


« Reply #3 on: 29 May '12 - 08:39 »
Reply with quoteQuote

Yes Smiley
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines