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

Mac OSX specific forum
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

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

Post 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?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

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

Post 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
macOS Catalina 10.15.7
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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%
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

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

Post 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.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

No Problem here...

PB v5.62 (x64)
Xcode 9.3
MacOS 10.13.4
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

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

Post 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
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

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

Post 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...
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Post Reply