Releasing images

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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #8311

    Hezkore
    Participant

    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:

    UPDATE: 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.

    #8348

    Mark Sibly
    Keymaster

    Yes, 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.

    #8356

    AdamStrange
    Participant

    mmmm, 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

    #8369

    abakobo
    Participant

    I 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.

    #8388

    Hezkore
    Participant

    @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. :/

    #8389

    abakobo
    Participant

    This 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/

    #8390

    Hezkore
    Participant

    Thanks abakobo!
    Some functions/methods there I didn’t know about. 🙂

    #8393

    abakobo
    Participant

    Fragment 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.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.