Page 1 of 1
ScreenOutput() produces a Null value
Posted: Sat Apr 19, 2008 8:12 pm
by Foz
How do I get this example to work?
It's a fullscreen app, and when I press Alt-Tab, it then crashes at StartDrawing(ScreenOutput()), with "The specified output is NULL (0 value)."
Any clues why it happens and how to get around it?
Code: Select all
If InitSprite() = 0 Or InitSprite3D() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open DirectX", 0)
End
EndIf
OpenScreen(800, 600, 32, "Simple Product Selector")
Repeat
ClearScreen(-1) ; white background
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(400 - (TextWidth("Sample Title Here") / 2), 10, "Sample Title Here",0,0)
StopDrawing()
FlipBuffers(1)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
ForEver
Posted: Sat Apr 19, 2008 9:16 pm
by Trond
This doesn't crash, but it can't be brought back either:
Code: Select all
If InitSprite() = 0 Or InitSprite3D() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open DirectX", 0)
End
EndIf
OpenScreen(800, 600, 32, "Simple Product Selector")
Repeat
ClearScreen(-1) ; white background
If IsScreenActive() And StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(400 - (TextWidth("Sample Title Here") / 2), 10, "Sample Title Here",0,0)
StopDrawing()
FlipBuffers(1)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
Else
Delay(10)
EndIf
ForEver
Edit: Proper code.
Posted: Sat Apr 19, 2008 9:19 pm
by Foz
As an interesting note, if you use the default subsystem (DirectX 7) then when you alt-tab, it crashes immediately.
If you use the DirectX9 subsystem, it only crashes (with the same error) when you try to switch back into the program.
Posted: Sat Apr 19, 2008 10:50 pm
by Booger
Tis because, DirectX fullscreen exclusive, requires you to reload your media if the screen is lost. Since the Library does not keep the copies in memory, you should check to see if your program lost focus, and reload it yourself. When it regains focus.
You may have to cancel the screen, and re-init the screen to do so. It is best practice, as the user may have changed screen bit depth while being out of your program. Otherwise Directx itself may crash the system.
It is an issue with DirectX, not Purebasic.
Posted: Sat Apr 19, 2008 11:23 pm
by netmaestro
No issues or bugs, it's just what IsScreenActive() is for:
Code: Select all
If InitSprite() = 0 Or InitSprite3D() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open DirectX", 0)
End
EndIf
OpenScreen(800, 600, 32, "Simple Product Selector")
Repeat
If IsScreenActive()
ClearScreen(-1) ; white background
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(400 - (TextWidth("Sample Title Here") / 2), 10, "Sample Title Here",0,0)
StopDrawing()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
Else
Delay(1)
EndIf
FlipBuffers(1)
ForEver
Posted: Sat Apr 19, 2008 11:44 pm
by Foz
Ahhh! Thanks for that, I didn't realise that I needed the flipbuffers outside the If statement
You guys are the best - thanks!
~ Foz
Posted: Sat Apr 19, 2008 11:48 pm
by netmaestro
Yes, FlipBuffers handles the screen events and so must always be called.