PixMap->Image bug

About Monkey 2 Forums Monkey 2 Programming Help PixMap->Image bug

This topic contains 9 replies, has 5 voices, and was last updated by  Mark Sibly 3 years ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1697

    jondecker76
    Participant

    I’ve been trying to work with a PixMap then load it as an image to display on the screen.  After trying everything with my current project, I decided to make something very simple to see what is going on:

    This will bomb out with an error

    Invalidate PixelFormat
    {{!DEBUG!}}

    #1726

    Pakz
    Participant

    Same error here to.

    Your clear color part. Is it not so that monkey has colors between 0.0 and 1.0? I changed that and it did not work either.

     

    edit:

    If you remove the textureflags.dynamic part then it does work.

    #1727

    jondecker76
    Participant

    Good point – I actually didn’t know that that the Color class worked in 0.0 to 1.0 for the R G B aspects, the documentation wasn’t clear.  But looking at color.monkey2 I can see you’re right.  Either way,  there seems to be a problem converting from pixmap colorspace to Image colorspace somewhere in the mojo code

    #1757

    Pakz
    Participant

    I modified the code a bit and it slows the computer down a lot. Maybe a memory leak?

    In release mode it slows to a crawl.

     

     

    How do you paste code?

    #1758

    Jesse
    Participant

    How do you paste code?

    Click on the “<>” above the posting box. Just enter the code don’t click on anything  and press Add.

    #1760

    Pakz
    Participant

    Thanks. I put the code in the codebox.

    #1761

    Jesse
    Participant

    I don’t think it’s a good idea to create a pixmap and an image from the pixmap every frame specially of that size. Creating the pixmap, clearing it, and converting it to an image are very intense operations.

    #1765

    Ethernaut
    Participant

    I don’t think it’s a good idea to create a pixmap and an image from the pixmap every frame specially of that size

    Agreed, if all you want to do is draw to a texture, try using an Image Canvas. There’s an example in the Bananas folder.

    https://github.com/blitz-research/monkey2/blob/master/bananas/rendertoimage/rendertoimage.monkey2

    Also, make sure you use the TextureFlags.Dynamic flag on that texture when drawing to an image canvas that is updated every frame.

    #1767

    Pakz
    Participant

    It is just a test. Should locals not be freed automatically when the function is exited?

    i thought i did something similar with monkey 1 and that worked without slowing down.

    the texture flag gave a compile error as was in the first post here.

    #1768

    Mark Sibly
    Keymaster

    >Should locals not be freed automatically when the function is exited?

    You need to image.Discard() images when you’ve finished with them.

    This will be partially automated in future so you’ll be able to discard ‘groups’ of resources with one call, but for now images should be discarded manually.

    Some people think GC should deal with this, but I disagree. VRAM is precious and I don’t think it’s a good idea to trust the release of VRAM to the vaguaries of the GC system. In fact, this is a pretty good example of why – the app wont actually be consuming that much system ram, so it may well have alloced a LOT of VRAM by the time it gets around to GC-ing – by which time it may be too late.

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

You must be logged in to reply to this topic.