Jump to content

Timer callback keeps shared_ptr<Object> extra even when timer was destroyed. SlidingDoor example


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

Template map.

If you hit Enter before activating doors SlidingDoor count will be zero but if you do it after triggering a doors a count will be few dozens.

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

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

    RegisterComponents();
    auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto framebuffer = CreateFramebuffer(window);
    auto world = CreateWorld();

    WString mapname = "Maps/start.ultra";
    auto scene = LoadMap(world, mapname);

    std::weak_ptr<SlidingDoor> slidingDoor;

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {

        if (window->KeyDown(KEY_ENTER)) 
        {
            for (auto& entity : scene->entities)
            {
                if (entity && entity->GetComponent<SlidingDoor>())
                {
                    slidingDoor = entity->GetComponent<SlidingDoor>();
                    scene->RemoveEntity(entity);
                    Print(slidingDoor.use_count());
                    break;
                }
            }
        }
        world->Update();
        world->Render(framebuffer);

    }
    return 0;
}

 

Link to comment
Share on other sites

  • Solution

I am changing it so that event listeners store a weak pointer to an extra object and automatically self-delete if an extra object is defined but gets deleted elsewhere.

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

I think it is. I just checked with the source build.

You are opted into the beta branch on Steam, right?

The current build number of the editor on Steam is 485.

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