ScreenOutput() produces a Null value

Advanced game related topics
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

ScreenOutput() produces a Null value

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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.
Booger
Enthusiast
Enthusiast
Posts: 134
Joined: Tue Sep 04, 2007 2:18 pm

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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
BERESHEIT
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

Ahhh! Thanks for that, I didn't realise that I needed the flipbuffers outside the If statement :D

You guys are the best - thanks!

~ Foz
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yes, FlipBuffers handles the screen events and so must always be called.
BERESHEIT
Post Reply