Can anyone verify this crash too?

Just starting out? Need help? Post your questions and find answers here.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Can anyone verify this crash too?

Post by Christian Uceda »

Code: Select all

EnableExplicit

Procedure test()
  Define str_keypressed.s, lng_operationresult.i
  PrintN("Test, press esc key or the n key")
  Repeat
    str_keypressed.s = Inkey()    
    Delay(20)
  Until str_keypressed <> ""

  Select RawKey()
    Case 27, 78 ; esc and n key respectively
      PrintN("Info! Operation aborted buy the user.")
      lng_operationresult = #False
      Goto Finish
  EndSelect
  
  lng_operationresult = #True
  Finish:
  ProcedureReturn lng_operationresult
EndProcedure

If OpenConsole()
  PrintN(Str(Test()))
  CloseConsole()
EndIf
The code crashes both compiled or on the ide in versions 4.41 and 4.50 when exiting the test procedure.

The IDE catches the crash as "invalid memory access" in 4.41 and "illegal instruction (executing binary data?)" on 4.50
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Can anyone verify this crash too?

Post by netmaestro »

You cannot use GoTo to exit a Select block. It corrupts the stack. Also, please start queries like this in Coding Questions.
Last edited by netmaestro on Sun Aug 01, 2010 12:54 am, edited 1 time in total.
BERESHEIT
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Can anyone verify this crash too?

Post by mk-soft »

"Goto" a bad method to leave "Select… EndSelect. The use of "Break" is better. "Goto" caused into this case a Stackcorruption.

P.S Sorry, no break. It´s verfy late...
Last edited by mk-soft on Sun Aug 01, 2010 12:59 am, edited 1 time in total.
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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Can anyone verify this crash too?

Post by rsts »

I get the crash. I don't think it like your goto from within the select.

cheers
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: Can anyone verify this crash too?

Post by Christian Uceda »

Hi, thanks for the quick reply.

I will avoid using select in this specific situation.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Can anyone verify this crash too?

Post by netmaestro »

Try this:

Code: Select all

EnableExplicit

Procedure test()
  Define str_keypressed.s, lng_operationresult.i
  PrintN("Test, press esc key or the n key")
  Repeat
    str_keypressed.s = Inkey()    
    Delay(20)
  Until str_keypressed <> ""
  
  Select RawKey()
    Case 27, 78 ; esc and n key respectively
      PrintN("Info! Operation aborted buy the user.")
      lng_operationresult = #False
    Default 
      lng_operationresult = #True
  EndSelect
  
  ProcedureReturn lng_operationresult
EndProcedure

If OpenConsole()
  PrintN(Str(Test()))
  Print("Press any key to exit...")
  Input()
  CloseConsole()
EndIf
And welcome to the forums! :mrgreen:
BERESHEIT
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: Can anyone verify this crash too?

Post by Christian Uceda »

Hi,

Thanks for the welcome! :D

I'm certainly new here :D

Do not worry about the abobe code, it is just an example I made, please do not try to fix it, it is just illustrative of the crash, not the actual code on the program.

I appreciate your efforts anyway :D
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can anyone verify this crash too?

Post by IdeasVacuum »

Crashes v4.40x86 with "illegal instruction (executing binary data?)"

Only fails if the Goto is used, but you can use select:

Code: Select all

EnableExplicit

Procedure test()
  Define str_keypressed.s, lng_operationresult.i
  PrintN("Test, press esc key or the n key")
  Repeat
    str_keypressed.s = Inkey()   
    Delay(20)
  Until str_keypressed <> ""

  Select RawKey()
    Case 27, 78 ; esc and n key respectively
      PrintN("Info! Operation aborted by the user.")
      lng_operationresult = #False

    Default
    PrintN("Info! Operation not aborted")
    lng_operationresult = #True

  EndSelect
 
  ProcedureReturn lng_operationresult
EndProcedure

Define iGood.i = #True

If OpenConsole()
  PrintN(Str(Test()))
  Delay(2000)
EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: Can anyone verify this crash too?

Post by Christian Uceda »

Wow many thanks again!

You guys are overwhelmingly... great! (and fast) :D

I repeat, do not worry about the code, I'm using a different approach on the code now.

I Just wanted to report this in case the crash is something the developers needed to look at.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can anyone verify this crash too?

Post by luis »

That's why I was suggesting it to mention it in the manual

http://www.purebasic.fr/english/viewtop ... 04#p310704

because it's quite obvious you should not exit a procedure with a goto, but about the select/endselect it's not obvious at all, since some compilers implements the select using gotos or jump tables but without using the stack.

Would be nice to have clearly stated if there are other constructs who deserve special attention with gotos.

offtopic: would be also nice to know which native commands/functions are replaced with inline code by the compiler.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Can anyone verify this crash too?

Post by netmaestro »

Would be nice to have clearly stated if there are other constructs who deserve special attention with gotos.
Basically, Goto commands should be avoided in any file containing Purebasic sourcecode. It should be OK in a note to yourself, e.g. "goto store for milk".
BERESHEIT
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can anyone verify this crash too?

Post by luis »

I disagree, in a language without exceptions handling the GOTO is the only way to keep your sanity and to exit from deep-nested nice structured code when something bad happens without using disguised gotos like breaks or god-forbid "break n" or dubious flags to be checked at every level.

In those cases I find GOTOs to a common exit point in the proc where the cause of the error can then be analyzed and acted upon a lot easier to understand and maintain too.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Can anyone verify this crash too?

Post by netmaestro »

That's what the OnError lib is for :mrgreen:
BERESHEIT
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can anyone verify this crash too?

Post by luis »

In theory, but I don't know if you ever tried to use it...

I did and found too much problems with that. Even if you look at the manual you'll see it's better suited to trap fatal errors to be followed by the the program termination.

Not to mention sometime there are interactions with the debugger.

I found very unreliable trying to generate a custom error with RaiseError(), trapping it with OnErrorGoto() and actually trying to continue from here.

I prefer to avoid it.

That's exactly what I do without problems and without linking more code with a simple goto... or variation on the theme -> http://www.purebasic.fr/english/viewtop ... =3&t=42555
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Can anyone verify this crash too?

Post by blueznl »

luis wrote:I disagree, in a language without exceptions handling the GOTO is the only way to keep your sanity and to exit from deep-nested nice structured code when something bad happens without using disguised gotos like breaks or god-forbid "break n" or dubious flags to be checked at every level.

In those cases I find GOTOs to a common exit point in the proc where the cause of the error can then be analyzed and acted upon a lot easier to understand and maintain too.
Luis, now I disagree :-)

You see, Goto is evil :-)

Seriously, there's little need for Goto. If things are many levels deep, why not use an 'exit flag'? Something like...

Code: Select all

allisfine = #true
...
...
If ...
  If allisfine And ...
    While allisfine And ...
      ...
    Wend
  Endif
Endif
...
Thus far, I've never ever felt the need for Goto.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply