Yue Posted August 31 Posted August 31 -- 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. 1 Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted September 1 Posted September 1 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; } 1 Quote Let's build cool stuff and have fun.
Josh Posted September 1 Posted September 1 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 1 Quote Let's build cool stuff and have fun.
Yue Posted September 2 Author Posted September 2 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. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted September 2 Posted September 2 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. 1 Quote Let's build cool stuff and have fun.
Yue Posted September 2 Author Posted September 2 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. 1 Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Solution Josh Posted September 2 Solution Posted September 2 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; } 1 Quote Let's build cool stuff and have fun.
Recommended Posts
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.