Page 1 of 1
OpenScreen() fails
Posted: Sat Nov 23, 2013 12:31 pm
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.
Re: OpenScreen() fails
Posted: Sat Nov 23, 2013 1:20 pm
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
Re: OpenScreen() fails
Posted: Sat Nov 23, 2013 5:05 pm
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
Re: OpenScreen() fails
Posted: Sat Nov 23, 2013 6:12 pm
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.
Re: OpenScreen() fails
Posted: Sat Nov 23, 2013 7:37 pm
by rootuid
Thanks for all the answers. Interesting stuff to experiment with.