Page 1 of 1

Why does this program stop responding after CtrlAltDel ?

Posted: Sun Mar 01, 2020 5:51 pm
by whizza
Hi

Why does this program stop responding when CtrlAltDel used to start Task Manager?

Is there a way to make the program continue to run after CtrlAltDel?

Using Windows10 Home v1909 and PB5.71x64

Code: Select all


If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered) = 0
  MessageRequester("Error", "Can't open main window")
  End
EndIf  

If OpenWindowedScreen(WindowID(0), 100, 100, 600, 400, 0, 0, 0) = 0
    MessageRequester("Error", "Can't open main windowed screen")
  End
EndIf 

  SetWindowColor(0, RGB(0,0,127))

  TextGadget(0, 100, 10, 600, 80, "") 

  CreateSprite(0, 50, 50, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0,0,50, 50, RGBA(0,0,255,0))
  Circle(25, 25, 25, RGBA(255,255,255,255))
  StopDrawing()  
  
  x = 0
  move = 10
  
  Repeat
    
    FlipBuffers()
    
    ClearScreen(RGB(0,0,255))
     
    DisplaySprite(0, x, x)
    
    SetGadgetText(0, Str(x)) 
    
    x = x + move
    
    If x < 10
      move = 5
    EndIf
    
    If x > 340
      move = -15
    EndIf
  
    ExamineKeyboard()
    
  Until KeyboardPushed(#PB_Key_Escape)
  
  End
    

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Sun Mar 01, 2020 11:17 pm
by netmaestro
I am using Win10 and PB 5.72 b1, released on Jan 31 2020. I can reproduce this problem. But I shouldn't be able to because Fred posted "Fixed" on Jan 29:

Image

Perhaps a mod can move this to bug reports?

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Mon Mar 02, 2020 8:50 pm
by oreopa
That image confused me for a good while... lol

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Mon Mar 02, 2020 8:59 pm
by Fred
It works fine here, the code is wrong, you ABSOLUTELY need an event loop. I need to find a way to check if WindowEvent() has been called between 2 FlipBuffers because it's a recurring mistake.

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered) = 0
  MessageRequester("Error", "Can't open main window")
  End
EndIf 

If OpenWindowedScreen(WindowID(0), 100, 100, 600, 400, 0, 0, 0) = 0
    MessageRequester("Error", "Can't open main windowed screen")
  End
EndIf

  SetWindowColor(0, RGB(0,0,127))

  TextGadget(0, 100, 10, 600, 80, "")

  CreateSprite(0, 50, 50, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0,0,50, 50, RGBA(0,0,255,0))
  Circle(25, 25, 25, RGBA(255,255,255,255))
  StopDrawing() 
 
  x = 0
  move = 10
 
  Repeat
    
    Repeat
    Until WindowEvent() = 0
    
    
    FlipBuffers()
   
    ClearScreen(RGB(0,0,255))
     
    DisplaySprite(0, x, x)
   
    SetGadgetText(0, Str(x))
   
    x = x + move
   
    If x < 10
      move = 5
    EndIf
   
    If x > 340
      move = -15
    EndIf
 
    ExamineKeyboard()
   
  Until KeyboardPushed(#PB_Key_Escape)
 
  End

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Mon Mar 02, 2020 9:39 pm
by netmaestro
I didn't even read the code :oops: :oops: :oops:

Works fine with the window events added. My mistake.

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Mon Mar 02, 2020 10:34 pm
by BlindMan
Thanks Fred.

This is probably a common coding issue because programmers like myself do not fully understand why this is necessary.

Please can someone explain why adding

Repeat
Until WindowEvent() = 0

fixes the code. Would WaitWindowEvent(100) also fix the issue?

Does this fix need PB 5.72 b1?

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Tue Mar 03, 2020 10:06 am
by Fred
You're using a screen in a windowed environment so you need to process the window event as you would do in a regular app. As you want your game to be as fast as possible, you don't want to use a WaitWindowEvent() because it will actually wait for an event and could pause your game randomly.

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Tue Mar 03, 2020 10:54 am
by whizza
Does this fix need PB 5.72 b1? Yes.

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Tue Mar 03, 2020 12:36 pm
by Derren
No. It needs the code that Fred posted, which is also in the Help page of WindowedScreen, btw.

Re: Why does this program stop responding after CtrlAltDel ?

Posted: Tue Mar 03, 2020 12:59 pm
by BlindMan
On Win10x64, revised code did not work until recompiled with PB 5.72x64 b1 instead of 5.71x64.