Mine also crashed inside a FUNCTION
FUNCTION ToHardware&
(ImgName$
, X1%
, Y1%
)
at the _PUTIMAGE line.
* might want to check this for a memory leak as well. There’s no way to FREEIMAGE the _LOADIMAGE when _PUTIMAGE is done.
I think that I must be still be making elementary mistakes.
FUNCTION ToHardware&
(ImgName$
, X1%
, Y1%
)
FUNCTION ToHardware1&
(ImgName$
, X1%
, Y1%
) _PUTIMAGE (0, 0)-(X1%
- 1, Y1%
- 1), Temp2mg&
, TempImg&
Originally my FUNCTION was as in ToHardware1&, where Temp2mg& is explicitly freed after use. But then I thought I'd optimise program lines and moved the _LOADIMAGE directly into the _PUTIMAGE, thinking that _FREEIMAGE would not then be required. So you must always do _FREEIMAGE and never put _LOADIMAGE into a _PUTIMAGE? I will use this method in future.
Let’s change the example to something physical, to help illustrate the issue.
Instead of NEWIMAGE, let’s SawWood and make a plank.
Instead of LOADIMAGE, let’s PickUpPlank.
Instead of PUTIMAGE, let’s PaintPlank.
Instead of FREEIMAGE, let’s DropPlank
ThisBoard = SawWood(2,4,10) ‘saw wood to make a 2x4, 10 feet long.
PaintPlank (Top)-(Bottom), ThisBoard, PickUpPlank(“OffGround”)
DropPlank ThisBoard
Now, with this odd set of real world instructions, we:
1) Saw a new 2x4.
2) Paint the new 2x4 the same color as another plank we pick up off the ground.
3) Then we drop the new 2x4.
Now question: How many times do you think you can repeat this process? You never actually drop the board you picked up from the ground; you’re still holding it...
And compare my little example to your original code (FUNCTION ToHardware). ;)
*ANY TIME* you load a resource in memory, you want to be able to free it when finished. If not, you create a memory leak which will eventually doom your program.