fix memory leak by adding Free on font surface

This commit is contained in:
cuu 2019-05-06 00:01:12 +08:00
parent 8377acd017
commit d26152e14f
9 changed files with 22 additions and 7 deletions

View File

@ -471,7 +471,7 @@ func (self *BleListMessageBox) Draw() {
rect2_ := rect.Rect(x,y,w,h)
surface.Blit(self.CanvasHWND,my_text,&rect2_,nil)
my_text.Free()
}

View File

@ -383,7 +383,7 @@ func (self *WifiListMessageBox) Draw() {
rect_2 := rect.Rect(x,y,w,h)
surface.Blit(self.CanvasHWND,my_text,&rect_2,nil)
my_text.Free()
}
//---------WifiList---------------------------------

View File

@ -132,6 +132,11 @@ func (self *FootBar) ReadFootBarIcons( icondir string) {
it.AddLabel("game", self.LabelFont)
it.Adjust( self.IconWidth/2+i*self.IconWidth, self.IconHeight/2+2, self.IconWidth,self.IconHeight,0)
it.IconIndex = i
if val, ok := self.Icons[v]; ok {
if val.(*FootBarIconItem).ImgSurf != nil {
val.(*FootBarIconItem).ImgSurf.Free()
}
}
self.Icons[v] = it
}
}
@ -177,8 +182,10 @@ func (self *FootBar) UpdateNavText(texts string) {
my_text := font.Render(self.LabelFont, text_, true, self.SkinManager.GiveColor("Text"),nil)
final_piece = text_
if int(my_text.W) >= left_width {
my_text.Free()
break
}
my_text.Free()
}
fmt.Printf("finalpiece %s\n", final_piece)

View File

@ -104,6 +104,7 @@ func (self *Label) DrawCenter(bold bool) { // default bold is false
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
surface.Blit(self.CanvasHWND,my_text,rect_,nil)
my_text.Free()
}
func (self *Label) Draw() {
@ -114,5 +115,5 @@ func (self *Label) Draw() {
rect_ := rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
surface.Blit(self.CanvasHWND,my_text,&rect_,nil)
my_text.Free()
}

View File

@ -118,6 +118,7 @@ func (self *MessageBox) Draw() {
dest_rect := rect.Rect(x,y, word_width,word_height)
surface.Blit(self.CanvasHWND, word_surface, &dest_rect,nil)
word_surface.Free()
if len(words) == 1 {
x+=word_width
} else {

View File

@ -126,6 +126,7 @@ func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int
}
rect_ := rect.Rect(x,y,self.Width,self.Height)
surface.Blit(surf,word_surface,&rect_,nil)
word_surface.Free()
x += (word_width+space)
}
x = pos_x

View File

@ -70,5 +70,5 @@ func (self *TextItem) Draw() {
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
surface.Blit(self.Parent.GetCanvasHWND(),my_text,rect_,nil)
my_text.Free()
}

View File

@ -126,6 +126,7 @@ func (self *Textarea) BuildBlitText() {
linenumber += 1
blit_rows = append(blit_rows,[]string{})
}
t.Free()
}
if len(blit_rows) == 1 {
@ -182,7 +183,7 @@ func (self *Textarea) BlitText() {
rect_ := rect.Rect(x,y,0,0)
surface.Blit(self.CanvasHWND,t,&rect_,nil)
x += surface.GetWidth(t)
t.Free()
}
}
@ -210,11 +211,13 @@ func (self *Textarea) Cursor() {
break
}
x += surface.GetWidth(t)
t.Free()
}
c_t := font.Render(self.FontObj,"_",true,&color.Color{0,0,0,255},nil)
rect_ := rect.Rect(x+1,y-2,0,0)
surface.Blit(self.CanvasHWND,c_t,&rect_,nil)
c_t.Free()
}
func (self *Textarea) Draw() {

View File

@ -469,11 +469,13 @@ func (self *TitleBar) Draw(title string) {
title_text_surf := font.Render(self.TitleFont, self.Title, true, self.SkinManager.GiveColor("Text"),nil)
surface.Blit(self.CanvasHWND,title_text_surf, draw.MidRect(title_text_w/2+self.LOffset,title_text_h/2+(self.BarHeight-title_text_h)/2,title_text_w,title_text_h,Width,Height),nil)
title_text_surf.Free()
time_text_surf := font.Render(self.TimeFont, cur_time,true,self.SkinManager.GiveColor("Text"),nil)
surface.Blit(self.CanvasHWND, time_text_surf, draw.MidRect(Width-time_text_w/2-self.ROffset, time_text_h/2+(self.BarHeight-time_text_h)/2, time_text_w,time_text_h,Width,Height),nil)
time_text_surf.Free()
start_x := Width - time_text_w - self.ROffset - self.IconWidth*3 // close to the time_text
self.Icons["bluetooth"].NewCoord(start_x - self.IconWidth,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)