2d/3d fullscreen app crashes if window looses focus

Just starting out? Need help? Post your questions and find answers here.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

2d/3d fullscreen app crashes if window looses focus

Post by JonChaos »

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
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

What version of PB are you using? With 3.91 there are no mouse limitations, and same with the focus changes of the window in question. I do not yet know about full screen.

I cannot speak for 3.92, I dont use it.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

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
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

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
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

That's because you must code the mouse release code yourself and detect window / screen lost focus...
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

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

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
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

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
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

yes it works fine for 2d sprites
but as soon as i use initengine3d() i got the old problem
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

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.
Mat
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

In my 2D game i found out you have to make a large delay before you can load the sprites, so there's time for the screen to became active again and the sprites don't get messed up...

Procedure Load_Sprites()

Delay(2000) <---------- !!!!
load...
load...
load...

endprocedure
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

One good thing is that the 2d part was fixed with one of the last versions. :D

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 :lol:

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
Dark Mars Software
User
User
Posts: 68
Joined: Sat Jun 19, 2004 3:34 am
Location: USA
Contact:

Post by Dark Mars Software »

Best bet is to upgrade you PB 3.91 to PB to 3.94. That might solve your problem. Just use the smartupdate tool.
Post Reply