2d/3d fullscreen app crashes if window looses focus
2d/3d fullscreen app crashes if window looses focus
hi folks
im new to pb and im amazed how easy u can write small games
but there are two things which really annoy me
- if i create a windowed screen with the OpenWindowedScreen() func the mouse cursor cant leave the area of the window
this is as intended if the window is activ
but if the window looses the focus , for example if i press alt-tab to switch to anoter window
the mouse is still limited to the area of the former created window
- if i create a new screen (fullscreen ) for drawing sprites onto it with the OpenScreen() function everything works fine as long as i dont try to switch to another window or as long as no message from my instant messanger comes in
if that happends the programm crashes silently
i noticed the same behavior in the game restricted area so i fear there is no workaround for that problem
im new to pb and im amazed how easy u can write small games
but there are two things which really annoy me
- if i create a windowed screen with the OpenWindowedScreen() func the mouse cursor cant leave the area of the window
this is as intended if the window is activ
but if the window looses the focus , for example if i press alt-tab to switch to anoter window
the mouse is still limited to the area of the former created window
- if i create a new screen (fullscreen ) for drawing sprites onto it with the OpenScreen() function everything works fine as long as i dont try to switch to another window or as long as no message from my instant messanger comes in
if that happends the programm crashes silently
i noticed the same behavior in the game restricted area so i fear there is no workaround for that problem
its 3.91
its easy to reproduce the 2 events i spoke of
run the example project terrain.pb in the examples directory
for the problem with the mouse start it windowed and press alt-tab to switch the active window
the terrain window is not active any more but the mouse is still limited to the area the window was shown
to reproduce the second problem start the project full screen and hit alt-tab and watch it crash
its easy to reproduce the 2 events i spoke of
run the example project terrain.pb in the examples directory
for the problem with the mouse start it windowed and press alt-tab to switch the active window
the terrain window is not active any more but the mouse is still limited to the area the window was shown
to reproduce the second problem start the project full screen and hit alt-tab and watch it crash
Probably you can check if it is running full screen using Screen3DRequester_FullScreen and then see if the window/screen is active using GetForegroundWindow_() = WindowID() or IsScreenActive(). If it isn't active then don't do anything and use ReleaseMouse(0) to release the mouse. If it is active then starting drawing again and use ReleaseMouse(1).
Mat
hmm
i tried to catch the screen lost event and got it to the point where it doesnt crash any more
sadly when i reactivate the fullscreen window all i see is flickering
here is the code im workin with
i tried to catch the screen lost event and got it to the point where it doesnt crash any more
sadly when i reactivate the fullscreen window all i see is flickering
here is the code im workin with
Code: Select all
InitSprite()
InitKeyboard()
IncludeFile "Screen3DRequester.pb"
Procedure GUI_LoadGraphics()
LoadSprite(1, "Graphics\GUI.bmp")
EndProcedure
If Screen3DRequester()
pause = 0
GUI_LoadGraphics()
Repeat
ExamineKeyboard()
If pause = 0
DisplayTransparentSprite(1,0,0)
FlipBuffers()
EndIf
If IsScreenActive()=0
pause = 1
WaitWindowEvent()
Else
pause = 0
EndIf
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
End
I think you need to reload the sprites and redraw the screen when you return to the game, but i'm not positive
It seems to work ok though:

Code: Select all
InitSprite()
InitKeyboard()
IncludeFile "Screen3DRequester.pb"
Procedure GUI_LoadGraphics()
LoadSprite(1, "Graphics\GUI.bmp")
EndProcedure
If Screen3DRequester()
GUI_LoadGraphics()
oldscreenactive = IsScreenActive()
Repeat
ExamineKeyboard()
DisplayTransparentSprite(1,0,0)
FlipBuffers()
screenactive = IsScreenActive()
If screenactive <> oldscreenactive
If screenactive=0
Repeat
WaitWindowEvent()
FlipBuffers()
Until IsScreenActive()<>0
Else
GUI_LoadGraphics()
ClearScreen(0,0,0)
FlipBuffers()
ClearScreen(0,0,0)
EndIf
EndIf
oldscreenactive = screenactive
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
End
Mat
Me too. The same problem is mentioned in this thread:
viewtopic.php?t=8327
It's also discussed in this French thread:
http://purebasic.hmt-forum.com/viewtopic.php?t=225
And in the French thread they seem to have found a solution for the Sokoban3D game (great game btw!) which you can download and look through the sources from here:
http://perso.wanadoo.fr/comtois/Sokoban ... DFORUM.htm
So if anyone can read French, can you see if they say what they're doing about the problem in that thread (search for tab on the first page)? At a quick glance through the code it looks like they're using OpenWindowedScreen instead of OpenScreen so perhaps that is it.
viewtopic.php?t=8327
It's also discussed in this French thread:
http://purebasic.hmt-forum.com/viewtopic.php?t=225
And in the French thread they seem to have found a solution for the Sokoban3D game (great game btw!) which you can download and look through the sources from here:
http://perso.wanadoo.fr/comtois/Sokoban ... DFORUM.htm
So if anyone can read French, can you see if they say what they're doing about the problem in that thread (search for tab on the first page)? At a quick glance through the code it looks like they're using OpenWindowedScreen instead of OpenScreen so perhaps that is it.
Mat
One good thing is that the 2d part was fixed with one of the last versions.
Although i use only the 2d functions in Pb at the moment i played a bit with the 3d functions and i came to an solution for the crash.
With the new pb version it wont crash anymore if u only called initengine3d().
It only crashed when a camera was present at the time when i minimised the fullscreen app.
So i tried removing the camera when the app was minimised and there was no crashing anymore.
The only problem left is that i cant maximise the app anymore
I would apreciate any hint how to safely remove the camera so that the app can be maximised again after minimising.
@MrMat the workaround of the sokoban game is creating a windowed screen on a borderless window so its more a "make_it_look_like_fullscreen"-workaround

Although i use only the 2d functions in Pb at the moment i played a bit with the 3d functions and i came to an solution for the crash.
With the new pb version it wont crash anymore if u only called initengine3d().
It only crashed when a camera was present at the time when i minimised the fullscreen app.
So i tried removing the camera when the app was minimised and there was no crashing anymore.
The only problem left is that i cant maximise the app anymore

I would apreciate any hint how to safely remove the camera so that the app can be maximised again after minimising.
@MrMat the workaround of the sokoban game is creating a windowed screen on a borderless window so its more a "make_it_look_like_fullscreen"-workaround
-
- User
- Posts: 68
- Joined: Sat Jun 19, 2004 3:34 am
- Location: USA
- Contact:
Best bet is to upgrade you PB 3.91 to PB to 3.94. That might solve your problem. Just use the smartupdate tool.
Pong Master:Open Source Pong - 40% Complete