PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: A Funny Thing Happened On The Way To The Forum  (Read 327 times)

SeaVipe

  • Senior Member
  • ***
  • Posts: 397
  • Windows 10
A Funny Thing Happened On The Way To The Forum
« on: January 31, 2021, 01:35:03 PM »

The funny thing is that I was in the process of starting a new Visual Designer project in WinFBE 2.1.7 when, after several successful test compiles, during the processing of 3 nested For loops, WinFBE locked up, the screen went blank for several seconds then WinFBE crashed. At the same time, an unrelated app that was running also crashed. I say unrelated but it is a WinFBE project, just not the project in the editor during the crash.
Collateral damage: the 'unrelated app' and the entire WinFBE_Suite folder were also deleted from my hard drive and the WinFBE project is blank.


Here is the code:
Code: [Select]

Function cp_init() As Boolean
   
For R As UByte = 0 To 255
    For G As UByte = 0 To 255
        For B As UByte = 0 To 255
            ? r, g, b
        Next B
    Next G
Next R


Function = True


End Function


Something similar to this happened before but I can't find the original post.  ;)
UPDATE: It turns out that the use of UByte is most likely the problem. In the above code, the For loops are forever loops. Change to any other numeric type (Integer, UShort...) and the code works properly (if not slowly because of the print to console)
« Last Edit: January 31, 2021, 02:05:42 PM by SeaVipe »
Logged
Clive Richey
You're Either Part Of The Solution, Or You're The Problem.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: A Funny Thing Happened On The Way To The Forum
« Reply #1 on: January 31, 2021, 02:41:48 PM »

Holy smokes that was a scary post to ready the first time I saw it!

Yes, the whole byte/ubyte thing as a loop countered has been discussed before over ont he FB forums. The advice is to use Integers or Longs instead.

You can read about it here in the official documentation: https://www.freebasic.net/wiki/KeyPgFornext
Quote
Note: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds endvalue, which can never happen. For example, if you try to iterate an variable from 0 to 255, the loop will only break once the variable reaches 256 or more. Using a UByte variable for the counter wouldn't work, because although it can hold the numbers 0 to 255, it cannot hold 256. See Standard Data Type Limits to find the upper and lower limits for the standard data types.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 397
  • Windows 10
Re: A Funny Thing Happened On The Way To The Forum
« Reply #2 on: January 31, 2021, 03:41:18 PM »

Thanks, Paul. I thought I'd read something about that before.
Logged
Clive Richey
You're Either Part Of The Solution, Or You're The Problem.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!