QB64 Phoenix Edition
What am I doing wrong with _FreeImage? - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10)
+---- Thread: What am I doing wrong with _FreeImage? (/showthread.php?tid=1497)



What am I doing wrong with _FreeImage? - PhilOfPerth - 02-24-2023

I have written a small test using _loadimage and _FreeImage, and all goes well except when I try to clear the images (as I believe is necessary after using them).
I get an Illegal function call message at that point. Why is it so???
Code: (Select All)
Screen _NewImage(1500, 800, 32)

GetGridSize:
Locate 15, 66
Print "Choose a grid size, 1 to 4 (for 12, 20, 30 or 42 tiles)"
Play move$
Getsize:
_KeyClear: k = 0
While k < 1
    _Limit 30
    k = _KeyHit
Wend
Select Case k
    Case Is = 49
        numtiles = 12 '                                                                      numtiles is number of tiles for that size grid
        numcols = 3 '                                                                        numcols is number of columns in the grid
    Case Is = 50
        numtiles = 20
        numcols = 5
    Case Is = 51
        numtiles = 30
        numcols = 5
    Case Is = 52
        numtiles = 42
        numcols = 7
    Case Else
        GoTo Getsize
End Select

DisplayTiles: '
numrows = numtiles / numcols '                                                                set number of rows needed for the numtiles and numcols
Dim tiles(numtiles) As Long
For a = 1 To numtiles
    tiles(a) = _LoadImage("RecPics/test.jpg", 32) '                                          set tiles array with numpics copies of test.jpg
Next
For a = 1 To numtiles / 2
    _PutImage (60 * a, 60), tiles(a) '                                                      display first half of tiles  array
Next
For a = numtiles / 2 + 1 To numtiles
    _PutImage (60 * (a - numtiles / 2), 120), tiles(a) '                                    display second half of tiles array
Next
Sleep 2

For a = 1 To numtiles
    _FreeImage (a) '                                                                            free all of the images from memory
Next
Print "I get an error message here: Illegal function call line 45 (the _FreeImage line)"
Sleep



RE: What am I doing wrong with _FreeImage? - bplus - 02-24-2023

Code: (Select All)
_FreeImage (a) '                         free all of the images from memory


Why is the "a" inside ()'s ?

_FreeImage is a Sub / Statement not a Function

If it's not that, DIM a as Long.

Oh! Should be:
_FreeImage tiles(a) ' <<< missing tiles


RE: What am I doing wrong with _FreeImage? - a740g - 02-24-2023

You should check if all _LoadImage calls are succeeding.

I am quite certain that _FreeImage is throwing an "illegal function call" because it is trying to free an invalid image handle.

Update:
Quote:Oh! Should be:

_FreeImage tiles(a) ' <<< missing tiles

^this.  Big Grin


RE: What am I doing wrong with _FreeImage? - PhilOfPerth - 02-24-2023

(02-24-2023, 01:13 AM)bplus Wrote:
Code: (Select All)
_FreeImage (a) '                         free all of the images from memory


Why is the "a" inside ()'s ?

_FreeImage is a Sub / Statement not a Function

If it's not that, DIM a as Long.

Oh! Should be:
_FreeImage tiles(a)  ' <<< missing tiles

The "(a)" is the loop variable. It loads the same image into each of the tiles() positions - there's only one image, called test.jpg ( which I attached - I hope!) Edit: I mis-named the image, by including its path. it should just be "test.jpg".


RE: What am I doing wrong with _FreeImage? - PhilOfPerth - 02-24-2023

(02-24-2023, 06:00 AM)PhilOfPerth Wrote:
(02-24-2023, 01:13 AM)bplus Wrote:
Code: (Select All)
_FreeImage (a) '                         free all of the images from memory


Why is the "a" inside ()'s ?

_FreeImage is a Sub / Statement not a Function

If it's not that, DIM a as Long.

Oh! Should be:
_FreeImage tiles(a)  ' <<< missing tiles

The "(a)" is the loop variable. It loads the same image into each of the tiles() positions - there's only one image, called test.jpg ( which I attached - I hope!) Edit: I mis-named the image, by including its path. it should just be "test.jpg".

You got it b+! I didn't get what you meant by "missing tiles" - I thought you meant there were tiles missing ( apart from mine Big Grin), but then it dawned on me. 
You were both correct, of course - it was trying to free a mis-named image. Thanks both for your help.