Author Topic: MOD crashed my program!!!  (Read 7374 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: MOD crashed my program!!!
« Reply #30 on: February 05, 2020, 05:34:20 am »
Wow guys, this is a bug issue that really does need to be addressed. I broke the code down further. It simply won't error trap the division by zero in the presence of a SELECT CASE.

Note: I just didn't define the pagemax variable, so it's zero.

Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  
  5. SELECT CASE a$(j)
  6.  

If you take out the SELECT CASE, it error traps properly. If you run it as is, above, it will crash.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: MOD crashed my program!!!
« Reply #31 on: February 05, 2020, 05:52:04 am »
Thanks for the thorough report and for carrying on with pursuing a minimal reproducible example, Pete. We're certain to investigate and hopefully find a fix before v1.4 comes out (no promises though, especially as it doesn't look trivial).

FellippeHeitor

  • Guest
Re: MOD crashed my program!!!
« Reply #32 on: February 05, 2020, 08:24:29 am »
Update: It crashed on me without an error box on Windows 10 64bit too.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MOD crashed my program!!!
« Reply #33 on: February 05, 2020, 09:06:48 am »
Right code crashes for me but this SELECT CASE does flag division by 0
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  
  5.  

and this
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  

and this
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2. DIM a(20)
  3. k = 1: a(k) = 42
  4.  
  5. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  6.  
  7.  
  8.  
  9.  

But not this, crashes:
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2. DIM a$(20)
  3. k = 1: a$(k) = "Nutz"
  4.  
  5. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  6.  
  7. SELECT CASE a$(k)
  8.  
  9.  

But this is OK?, well no crash back to division by 0
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2. DIM a$(20)
  3. k = 1: a$(k) = "Nutz"
  4. b$ = a$(k)
  5. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  6.  
  7.  
  8.  
  9.  
  10.  

Again back to division by 0 with SELECT CASE
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  
  5.  
  6.  
  7.  
  8.  

b() is not dim just like a$() but here division by 0 is flagged.
« Last Edit: February 05, 2020, 09:26:49 am by bplus »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: MOD crashed my program!!!
« Reply #34 on: February 05, 2020, 11:07:26 am »
Mine system is still giving me a Division by Zero error at run time, same as always, with all

examples in various versions of QB64.


Not sure if your wanting it in the IDE before compile, based on my lite  perusing of  the posts,

but I guess its an OS issue not giving you the appropriate error box at run time.

Again, feel as if this is a programmer responsibly to know what range of values their variables

are capable of returning, not the IDEs.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: MOD crashed my program!!!
« Reply #35 on: February 05, 2020, 11:16:35 am »
Hi Mark,

That's interesting. I tried some of those, and the only one I got to actually crash was when using a string array. It doesn't matter if it is or is not dimensioned, either.

PRINT "Press any key to test..."
SLEEP

IF i MOD pagemax = 0 THEN pagenum = pagenum - 1

SELECT CASE a$(1)
END SELECT

or...

PRINT "Press any key to test..."
SLEEP

IF i MOD pagemax = 0 THEN pagenum = pagenum - 1

DIM a$(1)
SELECT CASE a$(1)
END SELECT

----------------------------------------

Both examples using a string variable a$(1), in one example NO DIM and DIM in the other, crash. Just like your experiments, if I change a$(1) to just a$ or a, it properly reports division by zero, which occurs in the MOD statement for anyone just picking up on this thread.

Now it WON'T crash if you change SELECT CASE a$(1) to SELECT CASE VAL(a$(1))

So once we convert a string to a numeric value, QB64 is once again able to trap and display a division by zero error.

Also, this only seems to be happening when used in SELECT CASE. You can get rid of the SELECT CASE statement, and just put a PRINT a$(1) or put in a DO UNTIL a$(1) = "" : LOOP ... and it WON'T crash, either. So far, the only crash is with SELECT CASE.

@ COBALT: What OS are you running? One test Fell used was on a Windows XP 32-bit, and it didn't crash, but his 64-bit Win 10, which is what I'm using and I think what Mark is testing on, crashed. BTW - This isn't an IDE issue. It is only a compiled code issue. I agree with you the IDE should not be responsible for checking division by zero, especially when a variable is used as the divisor. Thanks for testing!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: MOD crashed my program!!!
« Reply #36 on: February 05, 2020, 11:26:44 am »
Windows  Vista(64bit) and 7(64bit).  QB64x32 Versions 1.1release, 1.1\82 (with my own adds), 1.2, 1.3, 1.3dev, and 1.4 RC.

they all give Divide by Zero error box at run time.

Probably something else Microdorks messed up in Win 10.

Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MOD crashed my program!!!
« Reply #37 on: February 05, 2020, 11:27:14 am »
Hi Pete,

I just realized the DIM of arrays doesn't matter because QB64 gives you the first 10 free without DIM plus using j index when no value has been assigned is same as index 0.

so a$(j) evaluates to ""?

Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  
  5.  
  6.  
  7.  

BINGO! (It crashes from IDE on my win 10-64 Intel core i5 laptop running QB64 v1.3 standard issue)
« Last Edit: February 05, 2020, 11:31:48 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MOD crashed my program!!!
« Reply #38 on: February 05, 2020, 11:39:13 am »
OK guys check this one out!
Code: QB64: [Select]
  1. PRINT "Press any key to test..."
  2.  
  3. IF i MOD pagemax = 0 THEN pagenum = pagenum - 1
  4.  
  5.     CASE "b": PRINT "foo"
  6.  

You'll never guess what happens here!

Update: well I thought we'd be back to division by 0 but no, get crashes with string literals, no crashes with string variables, numbers or number variables.
« Last Edit: February 05, 2020, 12:02:18 pm by bplus »