About Monkey 2 › Forums › Monkey 2 Programming Help › Releasing images
This topic contains 7 replies, has 4 voices, and was last updated by
abakobo
1 year, 10 months ago.
-
AuthorPosts
-
May 27, 2017 at 9:49 pm #8311
My application just keeps eating more and more Ram.
It’s because I can’t seem to be able to release/discard an image I’m constantly redrawing.I have this pixmap that I’m updating.
And then an image that I generate with New Image(myPixmap)
But when I create a new image, the old one doesn’t seem to get removed.
So more and more Ram is used.I’ve tried myImage.Discard() and I’ve tried myImage.Release() but none of them seem to work.
Release() bugs out at “DebugAssert( _refs>0 )”
And Discard() seems to just make things weird?
For example, after Discard() I can’t seem to be able to write to my Pixmap anymore?
I even check if the Pixmap is okay and valid (which it is) but it still crashes at SetPixelARGB()I’ve also just tried myImage=Null
But Ram usage is constantly increased, so it’s not discarded properly.Anyways, how do I completely remove my image?
Here’s an example:
Monkey123456789101112131415161718192021222324252627282930313233343536#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField myPixmap:PixmapField myImage:ImageMethod OnRender(canvas:Canvas) OverrideApp.RequestRender()'myImage=Null 'Eats ram'If myImage Then myImage.Release() 'Crashes at "DebugAssert( _refs>0 )"'If myImage Then myImage.Discard() 'Uncomment this line and...If Not myPixmap ThenmyPixmap=New Pixmap(32,32)myPixmap.ClearARGB(0)EndifIf myPixmap ThenmyPixmap.SetPixelARGB(16,16,Int(Rnd(999999999))) '... It will crash heremyImage=New Image(myPixmap)Endifcanvas.DrawRect(canvas.Viewport,myImage)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndUPDATE: If I do myPixmap.Retain() when I create it, it seems Discard() works…
But I’m then instead spammed with “Binding discarded texture!” in the console constantly. :S
And I’m not sure it clears it properly from memory then either, as it seems to go up and down wildly.May 28, 2017 at 11:04 pm #8348Yes, this system needs a bit of work!
pixmap.Retain() works cleanly here, but you shouldn’t have to do that in the first place. Will be looking into this stuff very soon.
May 29, 2017 at 10:55 am #8356mmmm, your using a ‘global’ field pixmap and then creating in OnRender
when you declare the initial pixmap, create it there too
<span class=”crayon-r”>Field</span> <span class=”crayon-v”>myPixmap</span><span class=”crayon-o”>:</span><span class=”crayon-e”>Pixmap = new Pixmap(32,32)</span>
each time you render you are creating a ‘new’ image. this is probably where the leak is occurring as you are assuming that creating a new image deletes the old one?
Make sure all old images are released first
May 29, 2017 at 3:53 pm #8369I usualy use a canvas to draw to my image, that way I don’t have to use new unless it’s size changes. It’s less ressource hungry I think.
May 30, 2017 at 10:11 pm #8388@AdamStrange
The leak comes from creating the new Image, the Pixmap is fine.It’s okay creating the pixmap OnRender, it’s only created once anyways. (Since it’s testing if it’s been created)
The leak is at “myImage=New Image(myPixmap)”
Since the pixmap changes every frame, I need the new pixmap data into the image (or it’ll just show the old pixmap)
And you do that with New Image(yourPixmapHere), but it’s not releasing the previous image, so it just keeps eating more and more ram.But as I later found out (and as Mark mentioned), the Retain() function works in this situation.
It lets me use Discard() on the image before creating the new one, and Retain() keeps the pixmap from being released with the image.@abakobo
Yeah that usually seems to be the way to go!
But I tried what I’m doing by using a canvas first, but I need to plot a lot of pixels into the pixmap, and doing it on a canvas and then flushing the canvas seemed to be a lot slower than via a pixmap. :/May 30, 2017 at 10:38 pm #8389This julia set generator forum topic is about plot drawing. It uses pointers to pixmap to speed up plot by plot generation.
http://monkey2.monkey-x.com/forums/topic/julia-set-fractal-generator-optimisation-drawpoint/
May 30, 2017 at 10:45 pm #8390May 31, 2017 at 8:52 am #8393Fragment shaders should be the fastest method but mx2 has to be hacked in order to get them working (or go custo gl). And mojo has had a lot of changes these days so it should be better to wait a bit before rehacking it. Or wait for official custom glsl shaders support that I suppose will happen some day.
there’s a playaround here: http://monkey2.monkey-x.com/forums/topic/playing-with-shaders/
don’t know if it’s vertex or fragment shaders though. but it’s custom glsl. -
AuthorPosts
You must be logged in to reply to this topic.