![]() |
_FREEIMAGE Behavior - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: _FREEIMAGE Behavior (/showthread.php?tid=2261) |
_FREEIMAGE Behavior - TerryRitchie - 12-17-2023 I just ran across something that I did not either realize or should not be happening. When an image is freed using _FREEIMAGE the associated variable is not reset to zero but instead retains the negative value of the image assigned. Is this normal behavior? Code: (Select All) image1 = _NEWIMAGE(100, 100, 32) Is this correct? RE: _FREEIMAGE Behavior - MasterGy - 12-17-2023 it's a bit like that, maybe it's a bad example, but I could compare it to this. I will give you a note on which is written what to bring from the store (index note). Once you have brought the goods from the store, the paper is irrelevant from then on. no one will cross the line. It stays. The advantage is that it remains in case you want to look at what you had to buy later. why should the note be crossed out? ![]() RE: _FREEIMAGE Behavior - SMcNeill - 12-17-2023 It's normal behavior, and it's always been that way for us. I believe the main issue one might run into would be with something like the following: _FreeImage Foo _PutImage ,Foo Now, with the above, you're going to get an error message saying, "You're a dummy! You just freed that image!!" If the value was set to 0, then that's basically saying, "Put the Image(0) to...." And, as we all know, Image(0) tends to default to the current _DISPLAY or the _DEST, in most cases... Which probably isn't what you actually want to happen here. ![]() RE: _FREEIMAGE Behavior - TerryRitchie - 12-17-2023 (12-17-2023, 08:59 PM)MasterGy Wrote: it's a bit like that, maybe it's a bad example, but I could compare it to this. I will give you a note on which is written what to bring from the store (index note). Once you have brought the goods from the store, the paper is irrelevant from then on. no one will cross the line. It stays. The advantage is that it remains in case you want to look at what you had to buy later. why should the note be crossed out?I understand what you are saying. However, I can't think of an example of why I would need to later reference the value of an image that has been removed from memory. The assigning of values to images is handled by QB64 under the hood so you're not guaranteed to ever use the same value again for any subsequent images. I easily overcame this with a quick little subroutine: Code: (Select All) SUB RemoveImage (Image AS LONG) SUB FlipImage(Direction AS INTEGER, InImg AS LONG, OutImg AS LONG) IF OutImg THEN _FREEIMAGE OutImg ' remove any leftover image ... ... END SUB Even though OutImg was freed the value remained. Later in the code when more images get created one of them will be assigned to the value that OutImg still contains. This was causing all kinds of freaky things to happen until I figured out what the heck was going on, LOL. RE: _FREEIMAGE Behavior - TerryRitchie - 12-17-2023 (12-17-2023, 09:05 PM)SMcNeill Wrote: It's normal behavior, and it's always been that way for us.Yep, that makes perfect sense as to why the variable is not reset. I can't believe I have not noticed this behavior until now. Maybe an additional line in the _FREEIMAGE Wiki to mention that the associated variable will not get reset to 0 could be added. RE: _FREEIMAGE Behavior - SMcNeill - 12-17-2023 (12-17-2023, 09:15 PM)TerryRitchie Wrote:(12-17-2023, 09:05 PM)SMcNeill Wrote: It's normal behavior, and it's always been that way for us.Yep, that makes perfect sense as to why the variable is not reset. I can't believe I have not noticed this behavior until now. Maybe an additional line in the _FREEIMAGE Wiki to mention that the associated variable will not get reset to 0 could be added. https://qb64phoenix.com/qb64wiki/index.php/FREEIMAGE <-- How's that look? RE: _FREEIMAGE Behavior - SMcNeill - 12-17-2023 And knowing that, you might want to change your code to: Code: (Select All) SUB RemoveImage (Image AS LONG) RE: _FREEIMAGE Behavior - TerryRitchie - 12-17-2023 (12-17-2023, 10:05 PM)SMcNeill Wrote: And knowing that, you might want to change your code to:Good point! (12-17-2023, 10:03 PM)SMcNeill Wrote: https://qb64phoenix.com/qb64wiki/index.php/FREEIMAGE <-- How's that look? Yep, perfect. |