[SOLVED] Cleanup steps when opening/closing the framework

Hi!
I’m working on a project where Panda3d is used to display some data in a window that can be opened and closed. While testing, I noticed an increase in memory when opening and closing the window multiple times.
I made a small project where I just render 100 empty frames, then close the window over and over to reproduce the issue and noticed that every time I open/close a window opened with WindowFramework* window = framework.open_window(); my frames took longer to render. I found out that I’m actually rendering an extra frame per framework.do_frame( Thread::get_current_thread() ); call.

Is there some cleanup code that I’m missing, or did I stumble on a bug?
I’m on windows 10, using the version 1.10.14 of panda, here’s my code:


#include "pandaFramework.h"
#include "pandaSystem.h"
#include "config_prc.h"
#include "configPage.h"
#include "load_prc_file.h"
#include <iostream>

int main()
{
	while (true)
	{
		load_prc_file_data( "", "load-display pandagl\n\
									win-origin -2 -2\n\
									win-size 800 600\n\
									fullscreen #f\n\
									framebuffer-hardware #t\n\
									framebuffer-software #f\n\
									depth-bits 1\n\
									color-bits 1 1 1\n\
									alpha-bits 0\n\
									stencil-bits 0\n\
									multisamples 0\n\
									notify-level warning\n\
									default-directnotify-level warning" );

		// Open a new window framework
		PandaFramework framework;
		framework.open_framework();

		// Set the window title and open the window
		framework.set_window_title( "Dis be where I test panda" );
		WindowFramework* window = framework.open_window();

		for (int i = 0; i < 100; ++i)
		{
			framework.do_frame( Thread::get_current_thread() );
			framework.report_frame_rate( std::cout );
		}
		
		framework.close_framework();
	}
}

here’s the output from framework.report_frame_rate( std::cout ); when I render only 1 frame each time instead of 100 to make it more readable

Hi, welcome!

I’m wondering if some of the tasks are remaining added to the task manager.

Try:

framework.get_task_mgr().remove(framework.get_task_mgr().get_tasks());

This does fix the problem, thanks! All the default tasks were being re-added each time I opened the window ( first window had 4 tasks 2 chains, second one had 8 tasks 2 chains, and so on )

Looking at the AsyncTaskManager class I see that the destructor should be calling AsyncTaskManager::cleanup(). Is there a step that I’m missing or should closing the framework destroy the task manager?

Also, would calling framework.get_task_mgr().cleanup() be a cleaner (:smile:) way of removing all tasks? The comments mention that this function is intended to be called on destruction only.

Ah yeah, you’re right, I missed the existence of that method. That should be a cleaner way to handle this.

The default AsyncTaskManager is a singleton, so it is never destroyed.

I see, well, thank you for you answers, problem solved!