Skip to content

Commit

Permalink
Fix prev bitmap leak and use global data for res bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
wqweto committed May 22, 2019
1 parent d356459 commit 37655d6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ctxNineButton.ctl
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,10 @@ Private Function pvStartAnimation(ByVal sngDuration As Single, ByVal sngOpacity1
If Not pvPrepareBitmap(m_eState, m_hFocusBitmap, hNewBitmap) Then
GoTo QH
End If
If m_hPrevBitmap <> 0 Then
Call GdipDisposeImage(m_hPrevBitmap)
m_hPrevBitmap = 0
End If
m_hPrevBitmap = m_hBitmap
m_hBitmap = hNewBitmap
hNewBitmap = 0
Expand Down Expand Up @@ -1550,19 +1554,35 @@ EH:
Resume QH
End Function

Private Property Get pvNppGlobalData(sKey As String) As Long
Dim sBuffer As String

sBuffer = String$(50, 0)
Call GetEnvironmentVariable("_NPP_GLOBAL" & App.hInstance & "_" & sKey, sBuffer, Len(sBuffer) - 1)
pvNppGlobalData = Val(Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1))
End Property

Private Property Let pvNppGlobalData(sKey As String, ByVal lValue As Long)
Call SetEnvironmentVariable("_NPP_GLOBAL" & App.hInstance & "_" & sKey, lValue)
End Property

Private Sub pvSetStyle(ByVal eStyle As UcsNineButtonStyleEnum)
Const FUNC_NAME As String = "pvSetStyle"
Static hResBitmap As Long

On Error GoTo EH
pvSetEmptyStyle
If eStyle <> ucsBtyNone Then
If hResBitmap = 0 Then
hResBitmap = pvNppGlobalData("hResBitmap")
End If
If hResBitmap = 0 Then
With New cNinePatch
If Not .frBitmapFromByteArray(FromBase64Array(STR_RES_PNG1 & STR_RES_PNG2), hResBitmap) Then
GoTo QH
End If
End With
pvNppGlobalData("hResBitmap") = hResBitmap
End If
Select Case eStyle
'--- buttons
Expand Down

0 comments on commit 37655d6

Please sign in to comment.