Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:48 16 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Odd system freezing

Author Message
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 229
Posted: 12:09pm 21 Nov 2020
Copy link to clipboard 
Print this post

This program is to draw a grid, with a dot at the centre of each grid "cell".  It's running on 5.05.05 (so I appreciate this may be fixed in the RC firmware)

OPTION EXPLICIT ON
OPTION DEFAULT NONE

MODE 3,8
DIM gridSize As Integer  = 5
DIM lineWeight As Integer = 1
DIM lineColour As Integer = RGB(150,150,150)

DIM boxLeft As Integer = 10
DIM boxTop As Integer = 10
DIM boxCols As Integer  = 5
DIM boxRows As Integer  = 5
DIM boxWidth As Integer = (gridSize+lineWeight)*boxCols + lineWeight
DIM boxHeight As Integer = (gridSize+lineWeight)*boxRows + lineWeight
DIM boxLineWeight As Integer = 1
DIM boxLineColour As Integer = lineColour


DIM x As Integer = 0
DIM y As Integer = 0

PAGE WRITE 2
CLS
BOX boxLeft, boxTop, boxWidth, boxHeight, boxLineWeight, boxLineColour

IF lineWeight > 0 AND gridSize > 0 THEN
 DO
   LINE boxLeft+(x*(gridSize+lineWeight)),boxTop,boxLeft+(x*(gridSize+lineWeight)),boxTop+boxHeight-lineWeight, lineWeight, lineColour
   x=x+1
 LOOP UNTIL x > boxCols
 
 DO
   LINE boxLeft, boxTop+(y*(gridSize+lineWeight)), boxLeft+boxWidth-lineWeight, boxTop+(y*(gridSize+lineWeight)), lineWeight, lineColour
   y=y+1
 LOOP UNTIL y > boxRows
END IF
PAGE WRITE 0
BLIT boxLeft,boxTop,boxLeft,boxTop,boxWidth,boxHeight,2

'Colour the centre marker of each grid square
DIM cursorX As Integer = boxLeft+lineWeight
DIM cursorY As Integer = boxTop+lineWeight

FOR y=0 to boxRows-1
 FOR x=0 to boxCols-1
 
   PIXEL cursorX+(x*(gridSize+lineWeight))+(gridSize\2),cursorY+(y*(gridSize+lineWeight))+(gridSize\2),RGB(255,0,255)
 
 NEXT x
NEXT y

DO
LOOP UNTIL INKEY$<>""


I'm seeing some really strange behaviour with the Pixel line.  With the code above, my system hangs (to the point where I need to power off and remove the SD card to get the system to respond; but the line below works.


   PIXEL cursorX+(x*(gridSize+lineWeight))+(5\2),cursorY+(y*(gridSize+lineWeight))+(gridSize\2),RGB(255,0,255)
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3476
Posted: 12:50pm 21 Nov 2020
Copy link to clipboard 
Print this post

  elk1984 said  . . . It's running on 5.05.05 (so I appreciate this may be fixed in the RC firmware)


Surely there's little point in posting problems but not using the most recent release. Would anyone want matherp to spend his time checking out something which might not even be a problem in the current firmware?

~
Edited 2020-11-21 22:50 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10588
Posted: 01:26pm 21 Nov 2020
Copy link to clipboard 
Print this post

It is a day one bug that is still there. The workaround is to assign the calculated x,y values to variables and use the variables to pass to the pixel command
 
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 229
Posted: 01:54pm 21 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  It is a day one bug that is still there. The workaround is to assign the calculated x,y values to variables and use the variables to pass to the pixel command


Thank you, I'm still finding my way around the Maximite so wasn't sure.  Strangely enough it only seems to happen with the X coordinate.  The code below works:

PIXEL cursorX+(x*(gridSize+lineWeight))+(5\2),cursorY+(y*(gridSize+lineWeight))+(gridSize\2),RGB(255,0,255)


Is it advisable to calculate all parameters to the graphics commands, or is this confined to PIXEL?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10588
Posted: 04:41pm 21 Nov 2020
Copy link to clipboard 
Print this post

Found it.

The bug occurred because the expression for x was > 32 characters. There is complex code for all the drawing routines that checks to see if you have passed an array e.g. x() or a normal expression. This check assumed the maximum length of a variable i.e. 32 characters but of course an expression could be more than 32 characters so bad thing happened.

The workaround is to make sure any expression is less than 32 characters until I release the next beta. This is why your modified version worked. I'll put a note in the errata for V5.05.05.

Thanks for finding this - took me a bit of time to understand but it is an important fix
Edited 2020-11-22 02:42 by matherp
 
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 229
Posted: 04:47pm 21 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  Thanks for finding this - took me a bit of time to understand but it is an important fix


Glad to have helped out!
Edited 2020-11-22 02:48 by elk1984
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025