- it works fine if it's not in a DLL
- if it's in a DLL and loaded from that DLL, then any call to DrawText() in my Linux 64 bit machine increases memory; no other drawing functions cause a memory leak
- But when I try a minimal example, the example works in a DLL!
Minimal example:
Code: Select all
Procedure mainLoop()
If OpenWindow(0,20,20,800,600,"DrawText Memory Leak",#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
InitSprite()
LoadFont(0, "Glass TTY VT220", 14)
If OpenWindowedScreen(WindowID(0),0,0,800,600)
done=#False
Repeat
If StartDrawing(ScreenOutput())
DrawingFont(FontID(0))
s$=""
For i=1 To 60
s$=s$+Chr(Random(96)+32)
Next
DrawText(40,40, s$,RGB(Random(255),Random(255),Random(255)),RGB(0,0,0))
StopDrawing()
FlipBuffers()
EndIf
Repeat
Event = WindowEvent()
If Event=#PB_Event_CloseWindow
done=#True
EndIf
Until event=0
Delay(1)
Until done
EndIf
CloseWindow(0)
EndIf
EndProcedure
ProcedureDLL xMain()
mainLoop()
EndProcedure
Code: Select all
Import "main.so"
xMain()
EndImport
CallCFunctionFast(@xMain())
Now the following non-minimal, incomplete real-life code does not work:
Code: Select all
Procedure DrawVram ()
Protected i,wFactor,hFactor,x,y
Protected.f cwOffset
Protected.q ms
Protected s$
If StartDrawing(ScreenOutput())
If GetSpecial(#CLEAN_BACKGROUND)=#Background_Clean
Box(0,0,w*charwidth,h*charheight,getSpecial(#BACKGROUND))
EndIf
DrawingFont(FontID(#MainFont))
For i=0 To maxPos
wFactor=i%w
hFactor=i/w
Box(charwidth*wFactor,charheight*hFactor,charwidth,charheight,GetDirectBackColor(i))
s$=Chr(GetDirectChar(i))
cwOffset=Max((charwidth-TextWidth(s$))/2,0)
DrawText(charwidth*wFactor+cwOffset,charheight*hFactor,s$,GetDirectColor(i),GetDirectBackColor(i))
Next
If CursorShown()
If GetSpecial(#CURSOR_TYPE)=#Cursor_Overwrite
Box(GetCursorColumn()*charwidth, GetCursorLine()*charheight, charwidth, charheight,GetColor(GetCursorColumn(), GetCursorLine()))
s$=Chr(GetChar(GetCursorColumn(), GetCursorLine()))
cwOffset=Max((charwidth-TextWidth(s$))/2,0)
; DrawText(charwidth*GetCursorColumn()+cwOffset,charheight*GetCursorLine(),s$, GetBackColor(GetCursorColumn(), GetCursorLine()), GetColor(GetCursorColumn(), GetCursorLine()))
Else
Box(charwidth*GetCursorColumn()-1,charheight*GetCursorLine(), 2, charheight, GetColor(GetCursorColumn(), GetCursorLine()))
EndIf
EndIf
StopDrawing()
FlipBuffers()
needsRefresh=#False
EndIf
EndProcedure
Code: Select all
DrawText(0,0,"Hello world")
Does anybody have an idea what could go wrong here?
__________________________________________________
Spaces added
06.03.2018
RSBasic