I should first say that I am using PB 5.73 cause I want the original backend for now.
Anyway, I am making a game in PB that uses an OpenWindowedScreen(). Now for some really strange reason I can't figure out (nor can ChatGPT - it gives me random irrelevant stuff) why the call StartDrawing(ScreenOutput()) is failing randomly as if the window is no longer in existence, but I do not close the window or anything. The exact error is "StartDrawing(): The specified output is NULL (0 value)." It happens at random times throughout gameplay. It tends to happen after about 3 minutes, but it varies a bit. It's one of those scary intermittent problems that seems to have no rhyme or rhythm. Has anyone encountered anything like this before?
I will post the source of the game if I have to, but I wasn't planning on making the game open source. It's a pretty simple game, so I don't see why such a thing is happening.
StartDrawing(ScreenOutput()) the specified output is NULL
-
- User
- Posts: 79
- Joined: Thu Jan 16, 2020 10:47 pm
StartDrawing(ScreenOutput()) the specified output is NULL
My blog/software site: http://dosaidsoft.com/
Re: StartDrawing(ScreenOutput()) the specified output is NULL
Without code, just speculation is possible:
- ScreenOutput() must be called inside StartDrawing(). You can't call ScreenOutput() alone nor use the retured value.
- Have you enabled the Purifier of the Pure Basic debugger? The Purifier checks for invalid memory access which could happen at a different point of the source but affect the StartDrawing() call.
- Do you use Threads and do you call ScreenOutput() in a different thread than the screen was opened?
Last edited by STARGÅTE on Mon Sep 08, 2025 10:13 pm, edited 1 time in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- User
- Posts: 79
- Joined: Thu Jan 16, 2020 10:47 pm
Re: StartDrawing(ScreenOutput()) the specified output is NULL
Solved it!
The problem was that I was loading a font in the main drawing loop of the game. It was my mistake. I didn't know that would cause such strange random crashes. It kind of makes sense though cause loading a font might cause some type of delay or maybe asynchronous code execution. So the problem wasn't even on the line it was failing on. It was just happening there cause it was the line right after the font load call.
Here's the function so nobody makes the same mistake:
The problem was that I was loading a font in the main drawing loop of the game. It was my mistake. I didn't know that would cause such strange random crashes. It kind of makes sense though cause loading a font might cause some type of delay or maybe asynchronous code execution. So the problem wasn't even on the line it was failing on. It was just happening there cause it was the line right after the font load call.
Here's the function so nobody makes the same mistake:
Code: Select all
Procedure DrawScene()
Protected x, y, c, px, py
; Draw blocks (no grid lines)
For y = 0 To #Rows-1
For x = 0 To #Cols-1
c = Grid(x, y)
If c >= 0
px = x * #Size
; py = y * #Size
; apply falling offset in pixels
Protected offY.i = 0
If AnimActive
offY = Int(FallOffset(x, y))
EndIf
py = y * #Size + offY
; px, py already include falling offset
Select Grid(x, y)
Case 0 : DisplayTransparentSprite(#SprRed, px, py)
Case 1 : DisplayTransparentSprite(#SprGreen, px, py)
Case 2 : DisplayTransparentSprite(#SprBlue, px, py)
Case 3 : DisplayTransparentSprite(#SprYellow, px, py)
EndSelect
EndIf
Next
Next
; HUD
; <----- WAS LOADING THE FONT RIGHT HERE. FIXED.
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(MainFont))
DrawText(6, 10, "Score: " + Str(Score), #Black)
DrawText(8, 8, "Score: " + Str(Score), #White)
If AnimActive
DrawText(6, 50, #StrFalling, #Black)
DrawText(8, 48, #StrFalling, RGB(255,60,60))
Else
DrawText(6, 50, #StrNewQuit, #Black)
DrawText(8, 48, #StrNewQuit, #White)
EndIf
If GameOver
DrawText(6, 30, #StrGameOver, #Black)
DrawText(8, 28, #StrGameOver, #White)
Else
DrawText(6, 30, #StrRules, #Black)
DrawText(8, 28, #StrRules, #White)
EndIf
StopDrawing()
EndProcedure
My blog/software site: http://dosaidsoft.com/