Jump to content

Program gets progressivly slower


Cole Chapman
 Share

Recommended Posts

I put leadwerks in a canvas in MaxGUI and it was working fine, and I added UPS. At first the UPS says around 300, and then about 1 minute later it gets down to 60-ish and you can even see the decline in performance on the cube rotating, here is my code:

 

SuperStrict

Framework leadwerks.ENGINE
Import maxgui.drivers
Import brl.eventqueue
Import brl.timer

Local world:TWorld
Local gbuffer:TBuffer
Local camera:TCamera
Local mesh:TMesh
Local light:TLight
Local ground:TMesh
Local material:TMaterial

GCSetMode(2)

RegisterAbstractPath( "C:/Program Files (x86)/Leadwerks Engine SDK" ) 

SetGraphicsDriver GLGraphicsDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER

Local w:TGadget = CreateWindow("Easy GL Cube in a GUI window", 10, 10, 512, 512)

Local c:TGadget = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
c.setlayout 1, 1, 1, 1

SetGraphics CanvasGraphics(c)

world=CreateWorld()
If Not world RuntimeError "Failed to create world."

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2)

camera=CreateCamera()
PositionEntity camera,[0.0,0.0,-2.0]

material=LoadMaterial("abstract::cobblestones.mat")

mesh=CreateCube()
PaintEntity mesh,material

ground=CreateCube()
ScaleEntity ground,[10.0,1.0,10.0]
PositionEntity ground,[0.0,-2.0,0.0]
PaintEntity ground,material

light=CreateDirectionalLight()

RotateEntity light,[45.0,45.0,45.0]
Repeat
SetGadgetText(w, UPS())
WaitEvent()
Select EventID()
	Case EVENT_WINDOWCLOSE
		End
	Case EVENT_WINDOWSIZE
		SetGraphics CanvasGraphics(c)
		gbuffer = CreateBuffer(GraphicsWidth(), GraphicsHeight(), BUFFER_DEPTH | BUFFER_COLOR0 | BUFFER_COLOR1 | BUFFER_COLOR2)


EndSelect
RedrawGadget c
TurnEntity mesh, [AppSpeed() * 0.5, AppSpeed() * 0.5, AppSpeed() * 0.5]


If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit

UpdateAppTime()
UpdateWorld(AppSpeed())

SetBuffer(gbuffer)
RenderWorld()

SetBuffer(BackBuffer())
RenderLights(gbuffer)



Flip(0)

Forever

gbuffer=Null
FreeEntity light
GCCollect()
End

 

So I am asking why it does this, if anyone can help that would be great

Chapman7

Link to comment
Share on other sites

I don't know BlitzMax syntax, but it looks like you're creating lots of gbuffers possbily losing references to the old one

 

 

 

 

Is there any reason your WaitEvent() and select EventID() lines are inside your repeat loop? What would happen if the were before the loop?

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

Yeah I was just lookin at that myself, I took them both out so its just:

 

SuperStrict

Framework leadwerks.ENGINE
Import maxgui.drivers
Import brl.eventqueue
Import brl.timer

Local world:TWorld
Local gbuffer:TBuffer
Local camera:TCamera
Local mesh:TMesh
Local light:TLight
Local ground:TMesh
Local material:TMaterial

GCSetMode(2)

RegisterAbstractPath( "C:/Program Files (x86)/Leadwerks Engine SDK" ) 

SetGraphicsDriver GLGraphicsDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER

Local w:TGadget = CreateWindow("Easy GL Cube in a GUI window", 10, 10, 512, 512)

Local c:TGadget = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
c.setlayout 1, 1, 1, 1

SetGraphics CanvasGraphics(c)

world=CreateWorld()
If Not world RuntimeError "Failed to create world."

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2)

camera=CreateCamera()
PositionEntity camera,[0.0,0.0,-2.0]

material=LoadMaterial("abstract::cobblestones.mat")

mesh=CreateCube()
PaintEntity mesh,material

ground=CreateCube()
ScaleEntity ground,[10.0,1.0,10.0]
PositionEntity ground,[0.0,-2.0,0.0]
PaintEntity ground,material

light=CreateDirectionalLight()

RotateEntity light,[45.0,45.0,45.0]
Repeat
SetGadgetText(w, UPS())
RedrawGadget c
TurnEntity mesh, [AppSpeed() * 0.5, AppSpeed() * 0.5, AppSpeed() * 0.5]


If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit

UpdateAppTime()
UpdateWorld(AppSpeed())

SetBuffer(gbuffer)
RenderWorld()

SetBuffer(BackBuffer())
RenderLights(gbuffer)



Flip(0)

Forever

gbuffer=Null
FreeEntity light
GCCollect()
End

Still does the same thing

Link to comment
Share on other sites

yeah, its inside the look, and I was glancing at GCSetMode(2) I found out its a "Garbage Collecetor Mode" when set to 2, no memory is automaiticaly collected, I switched it to 1, and I am getting a steady performance and a higher FPS, So I do believe I got it now, thank you for taking a look at it though man! I really apreciate it :(

Link to comment
Share on other sites

i converted this to use framewerk and it works just fine.

SuperStrict

Framework leadwerks.framewerk
Import maxgui.drivers
Import brl.eventqueue
Import brl.timer

GCSetMode(2)

RegisterAbstractPath AppDir

SetGraphicsDriver GLGraphicsDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER

Local w:TGadget = CreateWindow("Easy GL Cube in a GUI window", 10, 10, 512, 512)

Local c:TGadget = CreateCanvas(0,0,w.ClientWidth(),w.ClientHeight(),w,0)
c.setlayout 1, 1, 1, 1

SetGraphics CanvasGraphics(c)

Global fw:TFramewerk = TFramewerk.Create()
If Not fw RuntimeError "Failed to initialize engine."
fw.renderer.SetSkybox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"))

PositionEntity fw.Main.camera, [0.0, 0.0, - 2.0]

Local material:TMaterial = LoadMaterial("abstract::cobblestones.mat")

Local mesh:TMesh = CreateCube()
PaintEntity mesh, material

Local ground:TMesh = CreateCube()
ScaleEntity ground, [10.0, 1.0, 10.0]
PositionEntity ground,[0.0,-2.0,0.0]
PaintEntity ground,material

Local light:TLight = CreateDirectionalLight()
fw.SetStats(0)
RotateEntity light,[45.0,45.0,45.0]
Repeat
       SetGadgetText(w, UPS())
       WaitEvent()
       Select EventID()
       	Case EVENT_WINDOWCLOSE
           	End
           Case EVENT_WINDOWSIZE
               SetGraphics CanvasGraphics(c)
       EndSelect
       RedrawGadget c

	TurnEntity mesh, [AppSpeed() * 0.5, AppSpeed() * 0.5, AppSpeed() * 0.5]

       If KeyHit(KEY_ESCAPE) Exit
       If AppTerminate() Exit

       fw.Update()
	fw.Render()

       Flip(0)
Forever

fw.renderer.gbuffer = Null
FreeEntity light
GCCollect()
End

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

If speed is really important, you can get a bit more speed out of it by replacing all of those calls to AppSpeed(). Saving AppTime() into a variable at the start of the loop, and just referencing that variable for the rest of the loop. Generally referencing a variable is faster than calling a function. Although, on a project as small as this, you won't notice any difference at all.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

yeah, its inside the look, and I was glancing at GCSetMode(2) I found out its a "Garbage Collecetor Mode" when set to 2, no memory is automaiticaly collected, I switched it to 1, and I am getting a steady performance and a higher FPS, So I do believe I got it now, thank you for taking a look at it though man! I really apreciate it :(

This is actually a good idea to use always GCSetMode(2) and do the freeing of memory by code. That would probably speed up LE also a lot, and get rid of those random bugs in Editor.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

GCSetMode(2) will cause a continuously increasing memory usage if you try to use it with Leadwerks Engine. I don't know if it's still the same but I had some gc related problems back in 2.24 when BlitzMax's multithreading feature was in the early stages of development. I tried to get libvlc to render a video to a texture and although it worked pretty well - the speed was awful due to BlitzMax's mt garbage collector - however, I think that might not be an issue in 1.36 anymore.

Link to comment
Share on other sites

Add a call to GCCollect() in your main loop.

 

I don't recommend using the auto GC mode because it is possible for it to cause crashes. The problem is object Delete() methods might be called at any time, and in the case of OpenGL or Newton objects, it might cause the program to delete these things during a sensitive routine when they are being used. It might do something like delete an OpenGL buffer while another buffer is being set, and it is possible this might cause a crash in some situations.

 

In the future I will add the deleted objects to a queue to be deleted during the UpdateWorld() routine, so they will be more safe in auto GC mode, instead of deleting them in the Object Delete() method.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Thanks to everyone who helped figure this out, I fixed what I was told to, put Garbage Collector in Loop, I am using DrawText instead of GadgetText for the Window Title, but now I have one more question. I figured it would be dumb to start a new topic, so Ill just say it, I am trying to add camera controllers, and I have ported the FPS controller to Blitz as well as tried some older camera code, and I cant figure out what the problem is

 

SuperStrict

Framework leadwerks.framewerk
Import maxgui.drivers
Import brl.eventqueue
Import brl.timer

RegisterAbstractPath "C:/Program Files (x86)/Leadwerks Engine SDK"
SetGraphicsDriver GLGraphicsDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER

Global FW:TFramewerk
Local W:TGadget
Local C:TGadget
Local MX:Float = 0.0
Local MY:Float = 0.0
Local Move:Int = 0
Local Strafe:Int = 0
Local Jump:Int = 0
Local Mesh:TMesh
Local Ground:TMesh
Local Light:TLight
Local Controller:Tcontroller
Local CameraRotation:TVec3 = Vec3(0)
Local ControllerPosition:TVec3 = Vec3(0)

W:TGadget = CreateWindow("Easy GL Cube in a GUI window", 10, 10, 800, 600)
C:TGadget = CreateCanvas(0, 0, W.ClientWidth(), W.ClientHeight(), W, 0)
C.setlayout 1, 1, 1, 1

SetGraphics CanvasGraphics(C)

FW:TFramewerk = TFramewerk.Create()
If Not FW RuntimeError "Failed to initialize engine."

FW.renderer.SetSkybox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"))
PositionEntity FW.Main.camera, [0.0, 0.0, - 2.0]

Controller = CreateController(1.8, 0.4, 0.5, 45)

Mesh:TMesh = CreateCube()
Ground:TMesh = CreateCube()
Light:TLight = CreateDirectionalLight()
FW.SetStats(0)

ScaleEntity Ground, [10.0, 1.0, 10.0]
PositionEntity Ground, [0.0, - 2.0, 0.0]
RotateEntity Light, [45.0, 45.0, 45.0]

Repeat
	GCSetMode(2)
	UpdateAppTime()
       WaitEvent()
       Select EventID()
       	Case EVENT_WINDOWCLOSE
           	End
           Case EVENT_WINDOWSIZE
               SetGraphics CanvasGraphics(C)
       EndSelect
	RedrawGadget C

	MX = Curve(MouseX() - GraphicsWidth() / 2, MX, 3)
	MY = Curve(MouseY() - GraphicsHeight() / 2, MY, 3)
	MoveMouse(GraphicsWidth() / 2, GraphicsHeight() / 2)

	CameraRotation.X = Clamp(CameraRotation.X + MY / 5.0, - 89, 89)
	CameraRotation.Y = CameraRotation.Y - MX / 5.0
	RotateEntity(FW.Main.camera, CameraRotation)
	RotateEntity(Controller, Vec3(0, CameraRotation.Y, 0))

	If KeyDown(KEY_W)
		Move = 6
		If KeyDown(KEY_LSHIFT)
			Move = 2
		End If
	End If
	If KeyDown(KEY_S)
		Move = -5
		If KeyDown(KEY_LSHIFT)
			Move = 0
		End If
	End If

	Strafe = (KeyDown(KEY_D) - KeyDown(KEY_A)) * 8
	If KeyHit(KEY_SPACE) And ControllerAirborne(Controller) = False
		Jump = 4.7
	Else
		Jump = 0
	End If

	UpdateController(Controller, 0, Move, Strafe, Jump, 30, 0)
	ControllerPosition = EntityPosition(Controller)
	PositionEntity(FW.Main.camera, Vec3(ControllerPosition.X, ControllerPosition.Y + 1, ControllerPosition.Z))

	TurnEntity Mesh, [AppSpeed() * 0.5, AppSpeed() * 0.5, AppSpeed() * 0.5]

       If KeyHit(KEY_ESCAPE) Exit
       If AppTerminate() Exit

       FW.Update()
	FW.Render()
	DrawText("FPS: " + UPS(), 0, 0)
	DrawText("Camera Rotation X: " + CameraRotation.Z, 0, 20)
	DrawText("Camera Rotation Y: " + CameraRotation.Y, 0, 40)
	DrawText("Camera Rotation Z: " + CameraRotation.Z, 0, 60)
	DrawText("MX: " + MX, 0, 80)
	DrawText("MY: " + MY, 0, 100)
       Flip(0)
Forever

FW.renderer.gbuffer = Null
FreeEntity light
GCCollect()
End

 

The MX and MY are what screw it up

Link to comment
Share on other sites

For a flying camera, you should use a flying physics sphere, as it brings much smoother movement than raw entity movement. You can then also specify with what it should collide.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

  • 1 year later...

Bringin this ol' thread back up. I had an example program stripped down and running and I noticed the cube rotating got slow so I threw in a DrawText UPS() to see how the FPS was doing and I noticed it was getting slow. I recalled that this issue happened a while back to me (This thread) so I revisited and put in the correction. However, even when I through in GCSetMod(2) in the loop, the UPS dropped progressively from over 1000 to just below 200 before I terminated it. Im going to paste my code and hopefully someone can shed some light :)

 

SuperStrict

Framework leadwerks.ENGINE

Local world:TWorld
Local gbuffer:TBuffer
Local camera:TCamera

GCSetMode(2)

RegisterAbstractPath( "C:/Leadwerks Engine SDK" ) 

Graphics(800,600)

world=CreateWorld()
If Not world RuntimeError "Failed to create world."
gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2)

camera=CreateCamera()
PositionEntity camera,[0.0,0.0,-2.0]

Repeat
GCSetMode(2)

If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit
UpdateAppTime()
UpdateWorld(AppSpeed())
SetBuffer(gbuffer)
RenderWorld()
SetBuffer(BackBuffer())
RenderLights(gbuffer)

DrawText (UPS(), 0, 0)
DrawRect MouseX(), MouseY(), 250, 250

Flip(0)

Forever

gbuffer=Null
GCCollect()
End

Link to comment
Share on other sites

Screw it, don't use any GC command in bmx, they only make things worse. I just wish bmx would never have implemented those.

You could also use the engine.dll from BlitzMax and get much more tested code, or just drop the whole BlitzMax which is not supported anymore anyway and use Code::Blocks C++.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Repeat 

       If KeyHit(KEY_ESCAPE) Exit 
       If AppTerminate() Exit 
       UpdateAppTime() 
       UpdateWorld(AppSpeed()) 
       SetBuffer(gbuffer) 
       RenderWorld() 
       SetBuffer(BackBuffer()) 
       RenderLights(gbuffer) 

       DrawText (UPS(), 0, 0) 
       DrawRect MouseX(), MouseY(), 250, 250 

       Flip(0) 

GCCollect()

Forever 

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Ah, yes GCCollect() makes more sense than calling GCSetMode() again.

 

I did both GCCollect AND removing all Garbage Collection codes and they both run on par with each other (I saw higher spikes with removing but it was only a few frames

So I need to know if not having GCCollect is okay and I guess what does it exactly do?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...