Jump to content

Delete Windows.


Go to solution Solved by Josh,

Recommended Posts

Posted
-- Get the display
local displays = GetDisplays()
local displayscale = displays[1]:GetScale()

-- Create a window
local style = WINDOW_TITLEBAR | WINDOW_CENTER
local window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)

-- Main loop
while not window:Closed() do
    if window:KeyDown(KEY_ESCAPE) then
        window = nil
        collectgarbage()
 window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)
 
    end
end

Not delete Window.


Imagen

  • Confused 1

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

Testing in C++, no problem found...

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char* argv[])
{
    //Get the display
    auto displays = GetDisplays();
    Vec2 displayscale = displays[0]->GetScale();

    //Create a window
    auto style = WINDOW_TITLEBAR | WINDOW_CENTER;
    auto window = CreateWindow("Example", 0, 0, 400 * displayscale.x, 300 * displayscale.y, displays[0], style);

    //Main loop
    while (window and window->Closed() == false)
    {
        if (window and window->KeyDown(KEY_SPACE)) window = NULL;
    }
    return 0;
}

 

  • Like 1

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

Posted

I know why it is happening. There are events in the event queue that are referencing this window. The problem goes away if you add this code to the main loop:

while PeekEvent() do WaitEvent() end

 

  • Like 1

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

Posted
18 hours ago, Josh said:

I know why it is happening. There are events in the event queue that are referencing this window. The problem goes away if you add this code to the main loop:

while PeekEvent() do WaitEvent() end

 

 

-- Get the display
local displays = GetDisplays()
local displayscale = displays[1]:GetScale()

-- Create a window
local style = WINDOW_TITLEBAR | WINDOW_CENTER
local window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)
local framebuffer = CreateFramebuffer(window)
-- Main loop
while not window:Closed() do

	 collectgarbage()
    if window:KeyDown(KEY_ESCAPE) then
        window = nil
       
		 window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)
 
    end

	while PeekEvent() do WaitEvent() end
end

The problem is partially solved in Lua, if I don't create a framebuffer, if I create the frame buffer the window persists, look.

image.thumb.png.848828c0d51c8a117eeaf931ec46568f.png

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

As long as the framebuffer stays in memory, it will keep the window in memory too, because you can't have a framebuffer without a window.

If you set the framebuffer variable to nil as well, then the window should disappear.

  • Confused 1

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

Posted
6 minutes ago, Josh said:

As long as the framebuffer stays in memory, it will keep the window in memory too, because you can't have a framebuffer without a window.

If you set the framebuffer variable to nil as well, then the window should disappear.

The same result continues, look.


 

-- Get the display
local displays = GetDisplays()
local displayscale = displays[1]:GetScale()

-- Create a window
local style = WINDOW_TITLEBAR | WINDOW_CENTER
local window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)
local framebuffer = CreateFramebuffer(window)
-- Main loop
while not window:Closed() do

	 collectgarbage()
    if window:KeyDown(KEY_ESCAPE) then
		  framebuffer = nil
        window = nil
      
		 window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)

    end

	while PeekEvent() do WaitEvent() end
end

Edit : The difference is that there is only one "ghost" window left, not so many are repeated.

  • Thanks 1

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

  • Solution
Posted

There are a few requirements.

  • You must clear the event list with PeekEvent / WaitEvent.
  • A new call to World:Render must be made before the window can be released, since the window handle is being used in the rendering thread. The window will then be sent back to the main thread so that it gets deleted in the main thread.
  • A garbage collection call must be made after the window handle is received back. The timing of this is unpredictable. It's best to just call the garbage collector every frame.
local displays = GetDisplays()
local displayscale = displays[1]:GetScale()

local style = WINDOW_TITLEBAR | WINDOW_CENTER
local window = CreateWindow("Example", 0, 0, 400 * displayscale, 300 * displayscale, displays[1], style)
local fb = CreateFramebuffer(window)

local world = CreateWorld();

while window:Closed() == false do
	while PeekEvent() do WaitEvent() end
	if window:KeyDown(KEY_SPACE) then
		window = CreateWindow("Example", window.position.x + 100, window.position.y + 100, 400 * displayscale, 300 * displayscale, displays[1], WINDOW_TITLEBAR)
		fb = CreateFramebuffer(window)
	end
	world:Render(fb)
	collectgarbage()
end

C++ version:

        #include "Leadwerks.h"

        using namespace Leadwerks;

        int main(int argc, const char* argv[])
        {
            //Get the display
            auto displays = GetDisplays();
            Vec2 displayscale = displays[0]->GetScale();

            //Create a window
            auto style = WINDOW_TITLEBAR | WINDOW_CENTER;
            auto window = CreateWindow("Example", 0, 0, 400 * displayscale.x, 300 * displayscale.y, displays[0], style);
            auto fb = CreateFramebuffer(window);

            auto world = CreateWorld();

            //Main loop
            while (window->Closed() == false)
            {
                while (PeekEvent()) WaitEvent();
                if (window->KeyDown(KEY_SPACE))
                {
                    window = CreateWindow("Example", window->position.x + 100, window->position.y + 100, 400 * displayscale.x, 300 * displayscale.y, displays[0], WINDOW_TITLEBAR);;
                    fb = CreateFramebuffer(window);
                }
                world->Render(fb);
            }
            return 0;
        }

 

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