Why does this program stop responding after CtrlAltDel ?

Just starting out? Need help? Post your questions and find answers here.
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Why does this program stop responding after CtrlAltDel ?

Post 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
    
Last edited by whizza on Mon Mar 02, 2020 11:50 am, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Why does this program stop responding after CtrlAltDel ?

Post 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?
BERESHEIT
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: Why does this program stop responding after CtrlAltDel ?

Post by oreopa »

That image confused me for a good while... lol
Proud supporter of PB! * Musician * C64/6502 Freak
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why does this program stop responding after CtrlAltDel ?

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Why does this program stop responding after CtrlAltDel ?

Post by netmaestro »

I didn't even read the code :oops: :oops: :oops:

Works fine with the window events added. My mistake.
BERESHEIT
BlindMan
User
User
Posts: 32
Joined: Thu Aug 30, 2018 11:34 am

Re: Why does this program stop responding after CtrlAltDel ?

Post 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?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why does this program stop responding after CtrlAltDel ?

Post 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.
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: Why does this program stop responding after CtrlAltDel ?

Post by whizza »

Does this fix need PB 5.72 b1? Yes.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Why does this program stop responding after CtrlAltDel ?

Post by Derren »

No. It needs the code that Fred posted, which is also in the Help page of WindowedScreen, btw.
BlindMan
User
User
Posts: 32
Joined: Thu Aug 30, 2018 11:34 am

Re: Why does this program stop responding after CtrlAltDel ?

Post by BlindMan »

On Win10x64, revised code did not work until recompiled with PB 5.72x64 b1 instead of 5.71x64.
Post Reply