I have the following as member variables of a UserControl for my football simulation game.
This UserControl simulates games and updates the screen with info as each game finishes. m_imRushing and the other variables listed above are the team logos associated with the stat leaders in each category (ranked 1 through 5). Drawing these images in Paint is what's causing my error (which comes in the form of "Parameter is not Valid").Code:Private m_Logo() As Image Private m_imPassing(5) As Image Private m_imRushing(5) As Image Private m_imReceiving(5) As Image Private m_imTackles(5) As Image
Here's more background information: I use m_Logo() to store the images of each team in the UCs Load event where m_League is an object my own class (CLeague) that stores all league information.
My ResizeLogo function takes the stored large logo and shrinks it so it fits nicely next to a player's name:Code:ReDim m_Logo(m_League.NumberOfTeams - 1) For x = 0 To m_League.NumberOfTeams - 1 m_Logo(x) = ResizeLogo(m_League.Team(x).Logo) Next
When the user clicks a button "Sim All Games" a loop is started to simulate each game of the weekCode:Private Function ResizeLogo(ByVal OriginalLogo As Image) ' Make a bitmap for the result. Dim bm_dest As New Bitmap(24, 24) '' Make a Graphics object for the result Bitmap. Dim gr_dest As Graphics = Graphics.FromImage(bm_dest) '' Copy the source image into the destination bitmap. gr_dest.DrawImage(OriginalLogo, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1) bm_dest.Dispose() gr_dest.Dispose() Return bm_dest End Function
So my member variables are set. I call Invalidate() after every game is simmed which is supposed to update the Logos. After about a minute of successful execution I receive the dreaded "Parameter not valid" error for the DrawImage call.Code:For x = 0 To GameCount - 1 'Tons of processing code not relevant m_imPassing(1) = m_Logo(m_League.Team(x).TeamIndex) m_imRushing(1) = m_Logo(m_League.Team(x).TeamIndex) 'etc... next
There's something about using the UCs member variables that's causing memory usage to build up. When I take out the logos drawing routine I can run through almost the entire week's worth of games before the error shows up (there may be another lesser leak as well, but one problems at a time for this post) Where is this memory buildup and how should I dispose it? I can't dispose m_imPassing and the other variables because I reuse them do to their scope. There are no IDisposable objects to dispose either.Code:Private Sub pnWeeklyLeaders_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnWeeklyLeaders.Paint Dim g As Graphics = e.Graphics Dim y As Byte Dim LogoSpace As Byte = 27 For y = 0 To 4 Dim LogoLocation As New Point(37, 82 + (y * LogoSpace)) If m_pbPassing(y) IsNot Nothing Then g.DrawImage(m_imPassing(y), LogoLocation) Next end sub
Thanks!
neef





Reply With Quote