Blitzmax slows down on random computer

BlitzMax Forums/BlitzMax Beginners Area/Blitzmax slows down on random computer

sweet_kungfuman(Posted 2015) [#1]
So my program experience slowdown on random computer, according to people who test the game it also happen in powerful pc too ... it happens rarely though, sometimes it's fixed with a simple restart, sometimes it's fixed with me sending a new game build(even though i didn't change any of the fundamental graphics related code) any ideas?

the first part is simply loading icon, followed by prompt to choose resolution & graphic driver, after that is the game loop

strict
Import "icon_import.o"

' -----------------------------------------------------------------------------
' SetIcon
' -----------------------------------------------------------------------------
'Needed externs
?win32
Extern "win32"
	Function ExtractIconA%(hWnd%,File$z,Index%)
	Function GetActiveWindow%()
	Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16"
End Extern
?

' -----------------------------------------------------------------------------
' SetIcon
' -----------------------------------------------------------------------------

Global ScreenWidth: Float
Global ScreenHeight: Float
Local bFullScreen: Int
Local iDriver: Int

AppTitle$="Choose Screen Mode"
Graphics 320,240,0
SetIcon(AppFile, GetActiveWindow())

DrawResolutionChoices()

If KeyDown(KEY_1) Then
	ScreenWidth = 1024
	ScreenHeight = 768
	bFullScreen = False
Else If KeyDown(KEY_2) Then
	ScreenWidth = 1280
	ScreenHeight = 768
	bFullScreen = False
Else If KeyDown(KEY_3) Then
	ScreenWidth = 1280
	ScreenHeight = 720
	bFullScreen = False
Else If KeyDown(KEY_4) Then
	ScreenWidth = 1366
	ScreenHeight = 768
	bFullScreen = False
Else If KeyDown(KEY_5) Then
	ScreenWidth = 1024
	ScreenHeight = 768
	bFullScreen = True
Else If KeyDown(KEY_6) Then
	ScreenWidth = 1280
	ScreenHeight = 768
	bFullScreen = True
Else If KeyDown(KEY_7) Then
	ScreenWidth = 1280
	ScreenHeight = 720
	bFullScreen = True
Else If KeyDown(KEY_8) Then
	ScreenWidth = 1366
	ScreenHeight = 768
	bFullScreen = True
End If

Cls()
FlushKeys()
DrawDriverChoices()
If KeyDown(KEY_1) Then
	iDriver = 1
Else If KeyDown(KEY_2) Then
	iDriver = 2
End If
SeedRnd MilliSecs()

'Joystick Components
JoyCount()

Local ElapsedTicks:Float = -1
'Timer Components
Local time:TTimer = CreateTimer(60)

If ( iDriver = 1 ) Then
 	SetGraphicsDriver D3D9Max2DDriver()
	If ( GetGraphicsDriver() = Null ) Then SetGraphicsDriver D3D7Max2DDriver()
	Graphics( ScreenWidth, ScreenHeight, bFullScreen )

Else
	SetGraphicsDriver GLMax2DDriver()
	GLGraphics( ScreenWidth, ScreenHeight, bFullScreen )
End If	
SetIcon(AppFile, GetActiveWindow())
SetBlend( AlphaBlend )

'Main Loop
Init()
Repeat
	WaitTimer(time)
	Cls
	Move()	
	Draw()
	Flip	
'Until KeyDown(KEY_ESCAPE) Or AppTerminate() Or ( Manager.WindowTitle.iExecuteCode = MAIN_EXIT )
Until AppTerminate() Or ( Manager.WindowTitle.iExecuteCode = MAIN_EXIT )
BGMPlayer.Stop()
EndGraphics()




xlsior(Posted 2015) [#2]
Do you happen to have any memory leaks?

(If you pull up task manager while the game is running, does it have an excessive amount of RAM claimed? running low on or even out of memory, can dramatically slow down a PC's speed when it starts hammering the virtual memory)


sweet_kungfuman(Posted 2015) [#3]
@xlsior mmm .. maybe that's the problem ... how to fix memory leaks? I'm using "list" and create the enemy with "new", after they're not used anymore in the game I remove them with "removelist". They're removed from the list but it seems that they're still in the memory ..

will appreciate any help!

edit 1: just want to add that people who has slowdown problem experience the slowdown right from the start, so it's not gradually

edit 2: the program starts with around 290k used & the leak is only 5-10k everytime it starts a new stage, there is less than 10 stages in the game, is it still possible to cause a slowdown with today's technology ?


xlsior(Posted 2015) [#4]
They're removed from the list but it seems that they're still in the memory .


Blitzmax will not return the memory back to the OS, but it will be re-used for other operations if you need it later in the program.



edit 2: the program starts with around 290k used & the leak is only 5-10k everytime it starts a new stage, there is less than 10 stages in the game, is it still possible to cause a slowdown with today's technology ?


Those amounts are trivial, so shouldn't be an issue at all.

Actually, just realized something else: I noticed that you're using joysticks -- don't have one myself so never dealt with it, but supposedly joycount() can lead to a huge slowdown in some cases, especially if you have a joystick that gets disconnected:

For some more info, see: http://www.blitzbasic.com/Community/posts.php?topic=82245


sweet_kungfuman(Posted 2015) [#5]
ooh! interesting! This indeed seems like a possible cause. I'll give it a try, thanks, xlsior!


TomToad(Posted 2015) [#6]
It is possible that something in the background is slowing down the system longer than 1/60th of a second. That would cause your game to slow down. By running the logic separately from the rendering, you could keep items moving the same rate even when the framerate drops.
Two common ways to do this would be 1: multiply all movement by number of logic frames, or 2: run the logic more than once before rendering to screen.
     Local Frames:Int = WaitTimer(Timer)
     For Local i:Int = 1 to Frames
          Move()
     Next
     Cls
     Draw()
     Flip


or
     Local Frames:Int = WaitTimer(Timer)
     Move(Frames)
     Cls
     Draw()
     Flip

...
Function Move(Frames:Int)
     PlayerX :+ XUnitsPerFrame * Frames
     PlayerY :+ YUnitsPerFrame * Frames
End Function



sweet_kungfuman(Posted 2015) [#7]
I see, thanks TomToad. That's an interesting coding technique! I'll try it if the gamepad fix fails :D.