OpenScreen() fails

Everything else that doesn't fall into one of the other PB categories.
rootuid
User
User
Posts: 51
Joined: Sat Nov 23, 2013 11:46 am

OpenScreen() fails

Post by rootuid »

I'm using PureBasic 5.21 LTS (MacOS X - x64). I have a couple of lines of code which is failing. What it should do is create a screen 640x480:

Code: Select all

; setup our Screen Width and Height here for easier tracking
#ScreenWidth  = 640
#ScreenHeight = 480

; Initialize the sprite and keyboard systems and a 640x480, 16-bit screen
If InitSprite() = 0 Or InitKeyboard() = 0 Or OpenScreen(#ScreenWidth,#ScreenHeight,16,"App Title") = 0
   MessageRequester("Error!", "Unable to Initialize Environment", #PB_MessageRequester_Ok)
   End
EndIf
When I attempt to execute it fails with Unable to Initialize Environment
[11:27:05] Waiting for executable to start...
[11:27:06] Executable type: MacOSX - x64 (64bit, Unicode)
[11:27:06] Executable started.
[11:27:10] The Program execution has finished.


Any ideas why ? thanks.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: OpenScreen() fails

Post by PB »

Actually, you don't know for sure that it's OpenScreen() failing.
Your code tests for 3 conditions at once, so any 3 of them are
possible for the failure. It could be the keyboard for all you know.

Run this instead, to see which component is returning 0 for failure:

Code: Select all

#ScreenWidth  = 640
#ScreenHeight = 480

sp=InitSprite()
ke=InitKeyboard()
sc=OpenScreen(#ScreenWidth,#ScreenHeight,16,"App Title")

; Initialize the sprite and keyboard systems and a 640x480, 16-bit screen
If sp = 0 Or ke = 0 Or sc = 0
  Debug sp
  Debug ke
  Debug sc
  MessageRequester("Error!", "Unable to Initialize Environment", #PB_MessageRequester_Ok)
  End
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Shardik
Addict
Addict
Posts: 2079
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: OpenScreen() fails

Post by Shardik »

PB's advice is correct. Nevertheless you should check whether your graphics hardware supports your chosen screen resolution. You might try the following code which additionally checks whether the chosen screen resolution is supported by your system:

Code: Select all

ChosenScreenWidth = 640
ChosenScreenHeight = 480
ChosenScreenDepth = 16

If InitSprite() = 0
  MessageRequester("Error", "Unable to initialize sprites")
ElseIf InitKeyboard() = 0
  MessageRequester("Error", "Unable to initialize keyboard")
ElseIf ExamineScreenModes() = 0
  MessageRequester("Error", "Unable to examine screen modes")
Else
  ScreenResolutionIsSupported = #False

  While NextScreenMode()
    If ScreenModeWidth() = ChosenScreenWidth And
      ScreenModeHeight() = ChosenScreenHeight And
      ScreenModeDepth() = ChosenScreenDepth
      ScreenResolutionIsSupported = #True
      Break
    EndIf
  Wend

  ChosenScreenResolution$ = Str(ChosenScreenWidth) + "x" +
    Str(ChosenScreenHeight) + "x" +
    Str(ChosenScreenDepth)

  If ScreenResolutionIsSupported
    MessageRequester("Info", "Your chosen screen resolution of " +
      ChosenScreenResolution$ + " is supported!")
  Else
    MessageRequester("Error", "Sorry, but your chosen screen resolution of " +
      ChosenScreenResolution$ + " is not supported on this system!")
  EndIf
EndIf
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: OpenScreen() fails

Post by netmaestro »

Any ideas why ? thanks.
Yep. It's going to be the depth. That won't run here on Windows either. Change your depth to 32 and bob's your uncle.
BERESHEIT
rootuid
User
User
Posts: 51
Joined: Sat Nov 23, 2013 11:46 am

Re: OpenScreen() fails

Post by rootuid »

Thanks for all the answers. Interesting stuff to experiment with.
Post Reply