DGL https://delphigl.com/forum/ |
|
Memory leak.... https://delphigl.com/forum/viewtopic.php?f=19&t=9236 |
Seite 1 von 1 |
Autor: | azrael11 [ Fr Mai 28, 2010 21:47 ] |
Betreff des Beitrags: | Memory leak.... |
I Start a project very simple. I use the dglOpenGL.pas for the main tamplete and the textures.pas. The program makes this simple thing. I have a cube in the middle of the screen. I use the virtual keys (with the form.keydown ) up and down. Up changes the image from a folder. The folder has at least 10.000 images. But is small near 100 kb. The images is in png format. My problem is when i change the image the memory doesn't freed. The texture some how stays inside the memory. So in sort time (the program stats with 19MB) i have 400 mb. Can someone tell me how can i solve this... here is the fuctinon to lad a png texture. Code: function LoadPNGTexture(Filename: String; var Texture : GLuint; LoadFromResource : Boolean) : Boolean; var //pData : Pointer; PNGImage : TPNGGraphic; BMP : TBitmap; Data : Array of LongWord; W, Width : Integer; H, Height : Integer; Line : ^LongWord; C : LongWord; begin PNGImage := TPNGGraphic.Create; try PNGimage.LoadFromFile(Filename); except MessageBox(0, PChar('Couldn''t load PNG - "'+ Filename +'"'), PChar('BMP Unit'), MB_OK); Exit; end; BMP := TBitmap.Create; BMP.pixelformat:=pf32bit; BMP.width:= PNGImage.Width; BMP.height:= PNGImage.Height; BMP.canvas.draw(0,0,PNGImage); Width :=BMP.Width; Height :=BMP.Height; SetLength(Data, Width*Height); For H:=0 to Height-1 do Begin Line :=BMP.scanline[Height-H-1]; // flip JPEG For W:=0 to Width-1 do Begin c:=Line^ and $FFFFFF; // Need to do a color swap Data[W+(H*Width)] :=(((c and $FF) shl 16)+(c shr 16)+(c and $FF00)) or $FF000000; // 4 channel. inc(line); End; End; BMP.Free; PNGImage.Free; Texture:=CreateTexture(Width, Height, GL_RGBA, addr(Data[0])); Result:= true; end; and here is the call from keydown Code: if Key = VK_UP then
begin if WherePointer <=0 then WherePointer := 1; if FileExists('pic'+WherePointer+'.png') then LoadTexture('pic'+WherePointer+'.png'',texCube,False) else LoadTexture(nopicture.png',TexCube,False) WherePointer := WherePointer - 1; end; ; |
Autor: | Lord Horazont [ Fr Mai 28, 2010 22:03 ] |
Betreff des Beitrags: | Re: Memory leak.... |
Do you call glDeleteTextures at some place, specifically before assigning a new texture to TexCube? greetings |
Autor: | azrael11 [ Fr Mai 28, 2010 22:30 ] |
Betreff des Beitrags: | Re: Memory leak.... |
Lord Horazont hat geschrieben: Do you call glDeleteTextures at some place, specifically before assigning a new texture to TexCube? greetings Thank you my friend i solve this problem... I use the glDeleteTextures before i call the LoadTexture and the problem solves thank you very very much .... Thanks... |
Seite 1 von 1 | Alle Zeiten sind UTC + 1 Stunde |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |