Active Forums => QB64 Discussion => Topic started by: Craz1000 on April 08, 2020, 10:37:46 pm
Title: Image color swap, Part 2
Post by: Craz1000 on April 08, 2020, 10:37:46 pm
The original post was locked. However I have an update on progress.
I originally asked for a way to swap colors on a sprite to keep me from photoshoping the same sprite numerous times for color effects. Petr gave me this function... which works flawlessly.
However I also happen to use this same function to make the sprites "flash" random colors when they take damage. The issue is when this is ran a few thousand times the game hard crashes without warning and without the "On Error" command catching it. When i run task manager the memory usage goes up and up until it reaches a point and the game window closes without warning. To be sure i disabled the use of this function and memory usage stays down and the game ran for two hours without a problem. _MEM is very new to me and I dont quite understand it yet.
So my questions are... 1)why is this happening? If it is using _MEMFREE to release m then in theory memory usage shouldn't climb like the way it is.
2)how could I fix this? and if not is there maybe a way to do this without using _MEM since i suspect that is the culprit.
Title: Re: Image color swap, Part 2
Post by: SMcNeill on April 08, 2020, 10:54:48 pm
swapcolor is creating a new image over and over with _COPYIMAGE, so you need to _FREEIMAGE the memory when you no longer need it.
Title: Re: Image color swap, Part 2
Post by: bplus on April 09, 2020, 12:01:17 am
Cool, I was just asking Qwerkey about this! :)
Title: Re: Image color swap, Part 2
Post by: Petr on April 09, 2020, 11:35:55 am
Hi. Try this repaired version, it run if your IDE use basic setting (background color is 0,0,170)
Title: Re: Image color swap, Part 2
Post by: Craz1000 on April 09, 2020, 01:23:26 pm
That fixed it. Thanks!
Title: Re: Image color swap, Part 2
Post by: bplus on April 09, 2020, 02:58:08 pm
You know if you just keep track of what images are one offs and free them, you can keep the original image which makes sense to me. Unless maybe you continue to change different colors in the new images created?
I think this might be very useful in future so I tested and created demo and added it to my Tool Box. https://www.qb64.org/forum/index.php?topic=1511.msg116787#msg116787
This definitely answers my question put to Qwerkey in Pi-In-The-Sky thread.