Page 1 of 1

StartDrawing(): The specified output is NULL (0 value)

Posted: Fri Mar 30, 2018 12:25 pm
by Shield
Hey :)

I have to use OSX for work and wanted to see how well PB works on it.
Was off to a great start, but I soon encountered a problem I have no solution for:
StartDrawing(): The specified output is NULL (0 value).

Code: Select all


Debug InitSprite()
Debug OpenWindow(0, 0, 0, 800, 600, "")
Debug OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

Repeat
    If WindowEvent() = #PB_Event_CloseWindow
        Break
    EndIf
    
    ClearScreen(0)
    StartDrawing(ScreenOutput())
    DrawText(10, 10, "TEST")
    StopDrawing()
    FlipBuffers()
ForEver
The weird thing is, it sometimes works properly and sometimes crashes with the error above.
Initialization is always successful.

Am I missing something silly or has this happened to anyone else?

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Fri Mar 30, 2018 12:56 pm
by Wolfram
The lines beginning with Debug will only compiled if the debugger is turned on.

Code: Select all

Debug InitSprite()
Debug OpenWindow(0, 0, 0, 800, 600, "")
Debug OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
if you want to see the result of a function you can do it in this way.

Code: Select all

status =InitSprite()
Debug status
status =OpenWindow(0, 0, 0, 800, 600, "")
Debug status
status =OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
Debug status

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Fri Mar 30, 2018 1:28 pm
by mk-soft
Works by me...

Code: Select all

If InitSprite() = 0
  MessageRequester("Error", "InitSprite", #PB_MessageRequester_Error)
  End
EndIf

If OpenWindow(0, 0, 0, 800, 600, "") = 0
  MessageRequester("Error", "Openwindow", #PB_MessageRequester_Error)
  End
EndIf  

If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) = 0
  MessageRequester("Error", "OpenWindowedScreen", #PB_MessageRequester_Error)
  End
EndIf

#Framerate = 30
AddWindowTimer(0, 1, 1000/#Framerate)

Global trigger
Global lasttime, time, sync
lasttime = ElapsedMilliseconds()
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Timer
      Select EventTimer()
        Case 1
          time = ElapsedMilliseconds() - lasttime
          sync = 1000/#Framerate - time
          trigger + 1
          ClearScreen(0)
          StartDrawing(ScreenOutput())
          DrawText(10, 10, "Trigger " + trigger)
          DrawText(10, 40, "Time " + time)
          DrawText(10, 70, "Sync-Time " + sync)
          StopDrawing()
          FlipBuffers()
          lasttime = ElapsedMilliseconds()
      EndSelect
  EndSelect
ForEver
CPU: App 16%

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Sun Apr 01, 2018 1:11 pm
by Shield
Wolfram wrote:The lines beginning with Debug will only compiled if the debugger is turned on.
Yes, I know. :) I did that to check whether any of the Init/Open commands fail, they don't and they never do.

What I'm saying is: the code above works sometimes and sometimes doesn't, completely randomly,
and I have no idea why. Just rerunning it usually fixes the problem until it crashes again the next time I run it.

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Sun Apr 01, 2018 2:26 pm
by mk-soft
No Problem here...

PB v5.62 (x64)
Xcode 9.3
MacOS 10.13.4

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Sun Apr 01, 2018 5:36 pm
by Shield
@mk-soft

Your code from your first answer seems to work, however, when I remove the timer bit and change it to the following it starts crashing occasionally as well.
Could there some asynchronous initialization be going on behind the scenes where ScreenOutput sometimes gets called before everything is properly initialized?

Edit: Asked a friend to test and she encounters the same issue.

Code: Select all

If InitSprite() = 0
    MessageRequester("Error", "InitSprite", #PB_MessageRequester_Error)
    End
EndIf

If OpenWindow(0, 0, 0, 800, 600, "") = 0
    MessageRequester("Error", "Openwindow", #PB_MessageRequester_Error)
    End
EndIf  

If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) = 0
    MessageRequester("Error", "OpenWindowedScreen", #PB_MessageRequester_Error)
    End
EndIf


Global trigger
Global lasttime, time, sync
lasttime = ElapsedMilliseconds()
Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
            Break
    EndSelect
    time = ElapsedMilliseconds() - lasttime
    trigger + 1
    ClearScreen(0)
    StartDrawing(ScreenOutput())
    DrawText(10, 10, "Trigger " + trigger)
    DrawText(10, 40, "Time " + time)
    DrawText(10, 70, "Sync-Time " + sync)
    StopDrawing()
    FlipBuffers()
    lasttime = ElapsedMilliseconds()
ForEver

Re: StartDrawing(): The specified output is NULL (0 value)

Posted: Sun Apr 01, 2018 5:39 pm
by Shield
Alright, weird... :?

Really looks to me as if there is something asynchronous going on.
A Delay(200) just before the main loop seems to prevent the issue from occurring...