Jump to content

Texture::SetPixels memleak


Go to solution Solved by Josh,

Recommended Posts

Posted
#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
Posted

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.

Let's build cool stuff and have fun. :)

Posted

With the above sample (at least for me) the memory keeps growing constantly and later breaks the whole OS when no memory is left.

  • Sad 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

if you use this: 

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

you can see the memory grow in Gb steps ;)

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

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;
}

 

Let's build cool stuff and have fun. :)

  • Solution
Posted

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

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...