Jump to content

Texture::SetPixels memleak


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -3);

    auto texture = CreateTexture(TEXTURE_2D, 512, 512);
    auto pixmap = CreatePixmap(512, 512);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        texture->SetPixels(pixmap);
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

Using Texture::SetPixels (pixmap or buffer) leads to fast rising memory. 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

It might not be, but I will check. I have seen memory rise steadily for about ten seconds before it levels off. I think the Vulkan memory allocator just creates new buffers until some threahold is reached and it levels off. But I will test this and find out for sure.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, here is my test program. Of course, you can also see the memory usage if you have the VS diagnostics interface open:

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -3);

    auto texture = CreateTexture(TEXTURE_2D, 512, 512);
    auto pixmap = CreatePixmap(512, 512);

    uint64_t mem = 0;

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        auto mem2 = GetMemoryUsage();
        if (mem != mem2)
        {
            mem = mem2;
            Print(mem);
        }
        texture->SetPixels(pixmap);
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Solution

Okay, the cause was I had a memory pool system, but I stopped allocating buffers from the mempool and just started creating them instead, but I was still recycling old buffers back into the pool, so the size grew and grew.

I question whether a memory pool is really beneficial or needed on a modern OS, so I am just going to disable these completely.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...