Jump to content

Error disposing of item graphics.


Recoil

Recommended Posts

I never had all the exceptions on so I don't know if this was a problem on the original code.  I have tracked this down to InitGraphics I believe. Here is the way this was previously done:

        ReDim ItemIcons(0 To NumItems)
        ReDim ItemsGfx(0 To NumItems)
        ReDim ItemsGfxInfo(0 To NumItems)
        For i = 1 To NumItems

            ItemIcons(i).Init(New Bitmap(Application.StartupPath & GFX_PATH & ITEMS_PATH & i & GFX_EXT))
            If FileExist(Application.StartupPath & GFX_PATH & ITEMS_PATH & i & GFX_EXT) Then
            Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & ITEMS_PATH & i & GFX_EXT)

            End If

            TempBitmap = New Bitmap(Application.StartupPath & GFX_PATH & ITEMS_PATH & i & GFX_EXT)
            ItemsGfxInfo(i).Width = TempBitmap.Width
            ItemsGfxInfo(i).Height = TempBitmap.Height
            _transcolor = TempBitmap.GetPixel(0, 0)

            _memStream = New MemoryStream()
            TempBitmap.Save(_memStream, ImageFormat.Png)
            ItemsGfx(i) = New Texture(_memStream)
            _memStream.Dispose()
        Next

Here is the way I am doing it now:

        ReDim ItemIcons(0 To NumItems)

        For i = 1 To NumItems

            ItemIcons(i) = New OrionGfxControl(False)
            ItemIcons(i).Init(New Bitmap(Application.StartupPath & GFX_PATH & ITEMS_PATH & i & GFX_EXT))

        Next

I am using my control to make the icons.  It either has something to do with that, or this:

Does the (0 To NumItems) & (For i = 1 To NumItems) supposed to be the same?  If so I believe all of the init's are off in graphics.

Link to comment
Share on other sites

I will check shortly, but because there is no item(0) then it cannot dispose of the item.  As soon as I made that a 1 the problem stopped.  Of course I have more errors, mostly related to the connect, but that is another thread.  I will update this when I can.

Link to comment
Share on other sites

Yeah that makes sense. You didn't post the disposal code that was causing the error to appear. You are correct, since you never assign item index of 0 to anything, by removing it from your disposal loop you resolved the issue. Goodjob!

Link to comment
Share on other sites

I totally forgot about the disposal code...

For i = 1 To NumItems
            'If Not ItemsGfx(i) Is Nothing Then ItemsGfx(i).Dispose()
            ItemIcons(i).Disposer()
        Next

The commented out part is how it used to do it.  I left it in just in case there were any problems with my class drawing the items and spells.  My class file cuts down about 200 lines of drawing code I had for all of my panels...it make putting new panels in so much easier.

I have 103 images in my items folder...here is the code that pulls them:

Public Sub CheckItems()
        Dim i As Long
        i = 1

        While FileExist(Application.StartupPath & GFX_PATH & "Items\" & i & GFX_EXT)
            NumItems = NumItems + 1
            i = i + 1
        End While

        If NumItems = 0 Then Exit Sub
    End Sub

So yeah, I think because there is never an ItemGfx(0) then it was just going to keep with the error.  But a heads up to anyone else running into this issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...