PlanetSquires Forums

Support Forums => WinFBE - Code Editor and Visual Designer => Topic started by: SeaVipe on January 31, 2021, 01:35:03 PM

Title: A Funny Thing Happened On The Way To The Forum
Post by: SeaVipe 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)
Title: Re: A Funny Thing Happened On The Way To The Forum
Post by: Paul Squires 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.
Title: Re: A Funny Thing Happened On The Way To The Forum
Post by: SeaVipe on January 31, 2021, 03:41:18 PM
Thanks, Paul. I thought I'd read something about that before.