Page 2 of 3
Re: My game lags on Steam.
Posted: Sun Nov 23, 2025 5:04 pm
by miso
What if :
Code: Select all
Repeat : WaitWindowEvent(1) : ForEver
Re: My game lags on Steam.
Posted: Sun Nov 23, 2025 5:58 pm
by Joubarbe
miso wrote: Sun Nov 23, 2025 5:04 pm
What if :
Code: Select all
Repeat : WaitWindowEvent(1) : ForEver
I believed in that one for some reason, but no.
UPDATE: If anyone wants to help, please
download the demo, and try 1/ via the steam launcher 2/ via RH.exe. The world generation ("Generate hope") should take about 4 seconds via Steam, and be instant via RH.exe. If not, please report!

Re: My game lags on Steam.
Posted: Sun Nov 23, 2025 6:05 pm
by miso
I was hoping too...
Still belive, that the steam launcher somehow affects the os events. (It's a guess, and may be wrong assumption.)
Edit: What if you iterate trough all of the pending events in a loop? Is it possible in your code?
Re: My game lags on Steam.
Posted: Sun Nov 23, 2025 6:30 pm
by mk-soft
Your event loop is wrong ...
If you use an OpenWindowedScreen, the event loop must look different.
See PB-Help
Code: Select all
...
Repeat
; It's very important to process all the events remaining in the queue at each frame
;
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
Case #PB_Event_CloseWindow
Break 2
EndSelect
Until Event = 0
...
Forever
Re: My game lags on Steam.
Posted: Sun Nov 23, 2025 6:33 pm
by miso
He uses canvas, I'm not particularly familiar with it. So no screen as far as I know.
Re: My game lags on Steam.
Posted: Wed Nov 26, 2025 1:38 pm
by Joubarbe
This is a CPU trace from Visual Studio. You can see that the Steam overlay is doing something at a specific function. Is there a way in PureBasic to reproduce that and to have the name of the function? I'm in complete unknown territory there, so maybe there are other tools / methods to do that?
Re: My game lags on Steam.
Posted: Thu Nov 27, 2025 6:13 pm
by ricardo_sdl
Nice game!
From what I read, your game doesn't use Direct X or Opengl, right? It's just a normal windows executable, which uses the Canvas widget to draw stuff to the window, correct?
And which compiler version and options are you using to generate the exe?
Re: My game lags on Steam.
Posted: Thu Nov 27, 2025 7:36 pm
by minimy
But does the problem come from an update?
Did it work well before?
I think it's better to use WindowEvent() and put a Delay(1) before the end of the main loop. Instead of WaitWindowEvent(1). To process everything.
I don't know if this is the issue or not.

Re: My game lags on Steam.
Posted: Thu Nov 27, 2025 9:40 pm
by Joubarbe
ricardo_sdl wrote: Thu Nov 27, 2025 6:13 pm
Nice game!
From what I read, your game doesn't use Direct X or Opengl, right? It's just a normal windows executable, which uses the Canvas widget to draw stuff to the window, correct?
And which compiler version and options are you using to generate the exe?
Thanks! This is correct.
I compile in C with optimised code. Version is current non-beta.
It never worked before. It has always been slower on Steam.
WindowEvent() with a delay sounds to do exactly the same as WaitWindowEvent(1) to me, no?
Re: My game lags on Steam.
Posted: Fri Nov 28, 2025 1:55 am
by idle
maybe you need to generate output in a thread draw to image then post an event to set the image to canvas
it looks like it's hooking your window procedure by injecting a global hook via dll into your process.
So If it's hooking the window procedure to monitor events it may actually be tying to sync it at 60 FPS but if your code is taking to long, it could be adding a delta delay so it halves the frame rate to 30FPS, that doesn't really make any sense to me as a hook should return immediately but that could explain the observed results perhaps or perhaps its adding events to the event loop that PB normally eats?
So try threading the render to an image and post an event to grab the image to canvas or poll it so it grabs the image
Code: Select all
Global gmRender = CreateMutex()
Global width = DesktopScaledX(800)
Global height = DesktopScaledY(600)
Global gImg = CreateImage(#PB_Any,width,height,32)
Global gQuit
Procedure RenderGameFrame()
Static x,y,vx,vy
If vx = 0 : vx= 1 : EndIf
If vy = 0 : vy=1 : EndIf
If StartDrawing(ImageOutput(gimg))
Box(0,0,width,height,$FFFFFFFF)
DrawText(x,y,"Hello",RGBA(0,255,0,255),$FFFFFFFF)
StopDrawing()
EndIf
If x > width Or x < 0
vx = -vx
EndIf
If y > height Or y < 0
vy = -vy
EndIf
x+vx
y+vy
EndProcedure
Procedure RenderThread(*data)
Repeat
LockMutex(gmRender)
RenderGameFrame()
UnlockMutex(gmRender)
Delay(16)
Until gQuit
EndProcedure
Procedure GetFrame(gadget)
If TryLockMutex(gmRender)
If StartDrawing(CanvasOutput(gadget))
DrawImage(ImageID(gImg),0,0)
StopDrawing()
EndIf
UnlockMutex(gmRender)
Else
Debug "blocked"
EndIf
EndProcedure
#timerDraw = 123
OpenWindow(0,0,0,800,600,"test")
CanvasGadget(1,0,0,800,600)
AddWindowTimer(0,#timerDraw,16)
CreateThread(@RenderThread(),0)
Repeat
event = WaitWindowEvent()
If Event = #PB_Event_Timer And EventTimer() = #timerDraw
GetFrame(1)
EndIf
Until event = #PB_Event_CloseWindow
gQuit = 1
Also If your drawing anything on top of the canvas or overlapping any gadgets that could also be causing problems by generating to many invalidate rect events and flooding the event queue.
Main thing is to get your event loop free so it can process the events, if your blocking it by the time it takes to render a frame that could easily be the root of the problem
Toss it in a thread!
Re: My game lags on Steam.
Posted: Fri Nov 28, 2025 12:51 pm
by Joubarbe
Thanks a lot for your effort idle! My game only redraws when necessary, so I had to change your code a bit, as I cannot afford to redraw the whole UI at 60 FPS. So I did put all the rendering in a thread but unfortunately it still doesn't work.
The Steam support is apparently on it, but you never know with those guys... I'll update if they find a solution.
The only other solution I can think of at this point is to use a screen and make my app GPU friendly. But that's a serious refactoring...
Re: My game lags on Steam.
Posted: Fri Nov 28, 2025 11:50 pm
by idle
you could try this then using a semephore.
Code: Select all
Global gmRender = CreateMutex()
Global gsRender = CreateSemaphore()
Global width = DesktopScaledX(800)
Global height = DesktopScaledY(600)
Global gImg = CreateImage(#PB_Any,width,height,32)
Global gQuit
Procedure RenderGameFrame()
Static x,y,vx,vy
If vx = 0 : vx= 1 : EndIf
If vy = 0 : vy=1 : EndIf
If StartDrawing(ImageOutput(gimg))
Box(0,0,width,height,$FFFFFFFF)
DrawText(x,y,"Hello",RGBA(0,255,0,255),$FFFFFFFF)
StopDrawing()
EndIf
If x > width Or x < 0
vx = -vx
EndIf
If y > height Or y < 0
vy = -vy
EndIf
x+vx
y+vy
EndProcedure
Procedure RenderThread(gadget)
Repeat
WaitSemaphore(gSrender)
If Not gquit
RenderGameFrame()
If StartDrawing(CanvasOutput(gadget))
DrawImage(ImageID(gImg),0,0)
StopDrawing()
EndIf
EndIf
Until gQuit
EndProcedure
#timerDraw = 123
OpenWindow(0,0,0,800,600,"test")
CanvasGadget(1,0,0,800,600)
AddWindowTimer(0,#timerDraw,30)
CreateThread(@RenderThread(),1)
Repeat
event = WaitWindowEvent()
If Event = #PB_Event_Timer And EventTimer() = #timerDraw
SignalSemaphore(gsRender)
EndIf
Until event = #PB_Event_CloseWindow
gquit = 1
SignalSemaphore(gsRender)
Are you sure that your rendering is only happening on the intended events and isn't being called multiple times?
I hope the Steam guys take a look at it for you and it will be interesting to find out what the cause is.
Re: My game lags on Steam.
Posted: Mon Dec 08, 2025 8:39 am
by Joubarbe
Quick update: I've made a "screen" version of my game (hardware accelerated), and now the Steam overlay works and you can see the FPS at the top right corner of the screen, but the problem isn't fixed, because loading times (the most obvious slow downs) are still longer when the game is launched through Steam...

Re: My game lags on Steam.
Posted: Mon Dec 08, 2025 8:47 am
by miso
Well, thats a good news then.

Re: My game lags on Steam.
Posted: Mon Dec 08, 2025 10:19 am
by Joubarbe
miso wrote: Mon Dec 08, 2025 8:47 am
Well, thats a good news then.
Not at all, it didn't change anything

(you might have misread)