❄️🎁⛄ The Winter Games Tournament is Live! 🎄🎅❄️
Jump to content

Increased memory consumption when rotating a lot of instances of glb or glTF defined objects


Go to solution Solved by Josh,

Recommended Posts

Posted

Hi

Have experienced abnormal memory usage when having a lot of instances on screen and performing rotations on huge batches for testing performance. Rotating camera or translate in any direction does not allocate more memory. 

Rotation of instances (keeps increasing):

image.png.1123255312a36631230a8cd2b2d2bd0b.png

 

Translation and just camera movement/rotation :
image.png.d9e77ba13a4597d4f6cebc19bed6e4f3.png

 

Test program used (SPACE = toggle automati rotation/movement using WASD) :

#include "Leadwerks.h"

#define MAX_X   100
#define MAX_Y   100

using namespace Leadwerks;

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

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

    //Create a world
    auto world = CreateWorld();
    world->SetAmbientLight(1.0, 1.0, 1.0);

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

    auto cameraPivot = CreatePivot(world);
    cameraPivot->SetPosition(0.0, 0.0, 10.0);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetParent(cameraPivot);
    camera->Translate(0.0, 3.0, 0.0);
    camera->SetRotation(40.0, 0.0, 0.0);
    camera->SetClearColor(0.125);

    auto pivot = CreatePivot(world);
    pivot->SetPosition(0.0, 0.0, 0.0);

    auto tile = LoadModel(world, "Models\\Tile.glb");    // glb and glTF = consumes memory

//    auto tile = LoadModel(world, "Models\\Tile.obj");    // obj  = ok and so is creating cube internal in program inclusive applying materina
//    auto tile = CreateBox(world);
//    tile->SetCollider(NULL);
//    auto material = LoadMaterial("Materials\\Abstract\\MeasureGrid01.mat");
//    tile->SetMaterial(material);

    tile->SetScale(0.9, 0.9, 0.9);

    float centerX = MAX_X / 2.0;
    float centerY = MAX_Y / 2.0;

    for (int y = 0; y < MAX_Y; y++) {
        for (int x = 0; x < MAX_X; x++) {
            auto duplicate = tile->Instantiate(world);
            duplicate->SetParent(pivot);
            duplicate->SetPosition(-centerX + x, 0.0, -centerY + y);
        }
    }
    tile->SetHidden(true);

    float speed = 2.0f;
    bool moveCamera = false;
    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_SPACE))
            moveCamera = !moveCamera;

        if (moveCamera) {
            if (window->KeyDown(KEY_D)) cameraPivot->Move(speed, 0, 0);
            if (window->KeyDown(KEY_A)) cameraPivot->Move(-speed, 0, 0);
            if (window->KeyDown(KEY_W)) cameraPivot->Move(0, 0, speed);
            if (window->KeyDown(KEY_S)) cameraPivot->Move(0, 0, -speed);
        }
        else {
            //        pivot->Translate(0.1, 0.0, 0.0);    // Works
            pivot->Turn(0.0, 1.0, 0.0);    // Absorbs memory when loaded from glTF or glb. OK when loaded from obj or created inside program!!
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Attached is the files that are loaded from Models when testing (all stored using "save as" for the model in LW5 editor).

BR

Eirik

 

System = Windows 10, Gfx card = NVidia 1650, latest LW5.01 Pro Steam edition).

Tile.zip

  • Thanks 1
  • Solution
Posted

The problem had to do with extra NULL collision shapes being created in the physics thread. It will be fixed in the next build that goes up on the beta branch.

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