Jump to content

Memory Increase on Map change


Andy90
 Share

Recommended Posts

Hello, when you change a map the usage memory increase but never decrease. This means there is something allive what should not be allive. You can reproduce it with this code. Just hit multiple times T and see how the memory increases every time.

 

#include "UltraEngine.h"
#include "ComponentSystem.h"
//#include "Steamworks/Steamworks.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    
#ifdef STEAM_API_H
    if (not Steamworks::Initialize())
    {
        RuntimeError("Steamworks failed to initialize.");
        return 1;
    }
#endif

    RegisterComponents();

    auto cl = ParseCommandLine(argc, argv);
    
    //Load FreeImage plugin (optional)
    auto fiplugin = LoadPlugin("Plugins/FITextureLoader");

    //Get the displays
    auto displays = GetDisplays();

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

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

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

    //Load the map
    WString mapname = "Maps/start.ultra";
    if (cl["map"].is_string()) mapname = std::string(cl["map"]);
    auto scene = LoadMap(world, mapname);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);

#ifdef STEAM_API_H
        Steamworks::Update();
#endif

        if (window->KeyHit(KEY_T)) {
            scene = LoadMap(world, mapname);
        }

    }

#ifdef STEAM_API_H
    Steamworks::Shutdown();
#endif

    return 0;
}

 

  • Thanks 1
  • Upvote 1
Link to comment
Share on other sites

  • 9 months later...
  • 4 weeks later...
  • 4 weeks later...

I am done for the day, but I did solve several memory leaks in another issue...will examine this one soon.

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

In my first test, this does produce a memleak. This is my testing code.

Next I will test simpler scenes and see what is the cause.

#include "Leadwerks.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    RegisterComponents();

    auto cl = ParseCommandLine(argc, argv);

    //Get the displays
    auto displays = GetDisplays();

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

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

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

    //Load the map
    WString mapname = "Maps/memtest.map";
    if (cl["map"].is_string()) mapname = std::string(cl["map"]);
    auto scene = LoadMap(world, mapname);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);

        window->SetText(GetMemoryUsage(true));

        if (window->KeyHit(KEY_T)) {
            scene = LoadMap(world, mapname);
        }

        while (PeekEvent()) WaitEvent();// clear the events out
    }
    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

Interesting...even an empty map with no entities in it causes the memory usage to permanently increase by about 10,000 bytes each load...

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, so when I set the sun light color to black / 0, which causes the scene to not contain any directional light, the memory usage becomes stable. So we know directional lights are one cause of a mem leak.

memtest.zip

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

  • 2 weeks later...

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