Jump to content

Memory leak?


Yue
 Share

Go to solution Solved by Yue,

Recommended Posts

Memory remains where it was last time.  For example, if the game is paused, it goes up in value, but when you continue the game, it stays at the last value. If it was for example in 100, it goes up continuously until I continue the game, and it remains in for example in 500, if I pause it again it continues going up.

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Comment out parts of your code to find out what part is causing it. If the engine memory goes up without your code doing anything, then it would indicate a leak in the engine, but that's probably not the case.

It's also possible for memory usage to go up sometimes but then stabilize. This can happen when an object travels into an area of the world that does not have any octree structure initialized yet for that area or other data initialization things.

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 generally put a manual GC in my loop, on a 30 second timer I call "collectgarbage()" ..  but looking at your problem this may not help you as you have the symptoms of a genuine memory leak caused by some runaway code. 

Are you by chance using any Point Lights set to Static only ?

 

I'm only happy when I'm coding, I'm only coding when I'm happy.

Link to comment
Share on other sites

 

I only have a terrain, a directional light, the character and the vehicle.  The code is structured in the Input object, Player object, Rover object, Windows object.

But the strange thing is that it only happens when I pause the game and show the menu. Time::Pause().


 

//Code Main. 

#include "App.h"

using namespace Leadwerks;




int main()
{
	CWindow window("App Title", 1280, 720);
	
	CWorld menu;
	menu.LoadMap("Menu.map");
	CInput input;
	CRover rover(input);
	CGUI  gui(input);
	CPlayer player(input,rover,gui);
	
	

	// Bucle principal.
	while (!window.GetClosed())
	{
		
		if (input.GetKeyDown(Key::H))
		{
			return 0;
		}

		
		Time::Update();
		gui.Update();
		menu.Update();
		menu.Render();
		
		player.Update();
		rover.Update();

		window.ShowDebugInfo();
		player.DrawHand(window.GetContext());
		window.Update(false);

		
	}

	return 0;
}

GUI Show HIde Menu. 

#include "CGUI.h"

using namespace Leadwerks;

// Constructor.
CGUI::CGUI(CInput& input)
	:input(input)

{
	

	window = Window::GetCurrent();
    context = Context::GetCurrent();
	gui = GUI::Create(context);
	base = gui->GetBase();



	StartHUD();
	StartMenu();
	show = 0;
}

void CGUI::StartHUD()
{

	Widget* pnlHud = Widget::Panel(window->GetWidth() - 230, 10, 200, 100, base);

}

void CGUI::StartMenu()
{
	 pnlMenu = Widget::Panel(window->GetWidth()/2-250, window->GetHeight()-150, 500, 75, base);

	// Butons.
	btnStart   = Widget::Button("START", 10, 15, 150, 50, pnlMenu);
	btnOptions = Widget::Button("OPTIONS", pnlMenu->GetSize(true).x/2-75,15,150,50,pnlMenu);
	btnExit = Widget::Button("EXIT", pnlMenu->GetSize(true).x -160, 15, 150, 50, pnlMenu);
	
}

void CGUI::HideMenuStart()
{
	pnlMenu->Hide();

}

void CGUI::ShowMenuStart()
{

	pnlMenu->Show();
}


void CGUI::Update()
{
	HideMenuStart();

	

	if (show)
	{
		ShowMenuStart();
		Time::Pause();
	}
	else
	{
		HideMenuStart();
		Time::Resume();
	}

	if (input.GetKeyHit(Key::Escape))
	{
		show = 1 - show;

	}



}

bool CGUI::GetShow()
{

	return(show);
}

 

 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

void CGUI::Update()
{
	//HideMenuStart(); << Solved temporal.

	

	if (show)
	{
		ShowMenuStart();
		Time::Pause();
	}
	else
	{
		HideMenuStart();
		Time::Resume();
	}

	if (input.GetKeyHit(Key::Escape))
	{
		show = 1 - show;

	}



}

 

This partially solves the problem. When I uncomment that line of code it no longer uploads the memory when the game is paused. 

What happens now is that it goes up a little, for each time I make visible the start menu of the three buttons, the memory usage in C++ and in Script goes up. If someone has any idea why this happens I would appreciate it, or if it is something normal.

 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Try calling collectgarbage(), right after you resume the time.  See if it returns to the value it was at when you called a time:pause.

        HideMenuStart();
        Time::Resume();
        collectgarbage();

It sorta looks like to me you continuously calling 

 

		ShowMenuStart();
		Time::Pause();

Is ShowMenuStart() loading or creating anything each time it's called?

 

 

  • Thanks 1

I'm only happy when I'm coding, I'm only coding when I'm happy.

Link to comment
Share on other sites

8 hours ago, Alienhead said:

Try calling collectgarbage(), right after you resume the time.  See if it returns to the value it was at when you called a time:pause.

        HideMenuStart();
        Time::Resume();
        collectgarbage();

It sorta looks like to me you continuously calling 

		ShowMenuStart();
		Time::Pause();

Is ShowMenuStart() loading or creating anything each time it's called?

o.O??
image.thumb.png.76cd97bd67d0db429fc37e0193a6c634.png

 

1>------ Operación Compilar iniciada: proyecto: AstrocucoX, configuración: Release Win32 ------
1>cl : Línea de comandos warning D9035: La opción 'Gm' está desusada y se quitará en próximas versiones
1>cl : Línea de comandos warning D9030: '/Gm' es incompatible con el multiprocesamiento; se omitirá el modificador /MP
1>CGUI.cpp
1>f:\leadwerks\projects\astrocucox\source\cgui.cpp(51): error C3861: 'collectgarbage': no se encontró el identificador
1>Generando código...
1>Compilando...
1>CInput.cpp
1>Generando código...
1>Omitiendo... (no se detectaron cambios relevantes)
1>main.cpp
1>CWorld.cpp
1>CWindow.cpp
1>CRover.cpp
1>CPlayer.cpp
1>Compilación del proyecto "AstrocucoX.vcxproj" terminada -- ERROR.
========== Compilar: 0 correctos, 1 incorrectos, 0 actualizados, 0 omitidos ==========

 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

2 minutes ago, SpiderPig said:

I re-call this issue ages ago when my project was in Leadwerks.  I reckon it's a bug but you can try this in C++.  I can't remember if you can even call this function like this, but give it a go and see what happens.

System::CollectGarbage();
void CGUI::Update()
{
	
	pnlMenu->Show(); // Memory usage goes up uncontrollably.
	
	if (input.GetKeyHit(Key::Escape))
	{
		show = 1 - show;
		
	}


	if (show)
	{
		
		pnlMenu->Show();
		Time::Pause();
	
	}

	if(!show)
	{
		
		pnlMenu->Hide();
		Time::Resume();
	
	}




}

 

Nothing happens, the memory keeps going up. I have identified the one that causes the problem, it is when I try to display the panel that contains my three start menu buttons. 

Every time I show it the memory usage goes up, if I put inside the method it starts to go up uncontrolled. 

So how do I confirm that if it is a bug, by hiding the whole Gui I don't have that problem.

Gui->Hide(); No problem.

 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

  • Solution

I don't think Josh has time for this now, nor does he think he might be interested in it, the result is video I have in this thread, the memory goes up unchecked. The solution from my side is to create a GUI for each particular panel, menu, options etc.

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

On 8/3/2023 at 8:53 PM, SpiderPig said:

Yes he's focused on Ultra right now.  If you can work around it, that might be best for now.

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

model = Model:Box()
model:SetColor(0.0,0.0,1.0)


local gui = GUI:Create(context)
local base = gui:GetBase()
base:SetScript("Scripts/GUI/Panel.lua")
base:SetObject("backgroundcolor",Vec4(0,0,0,0.1))
pnl = Widget:Panel(300,100,200,200,base)

cam = Camera:Create()
while true do
        if window:Closed() or window:KeyHit(Key.Escape) then return false end

	Time:Pause()
	pnl:Hide()
        model:Turn(0,Time:GetSpeed(),0);

        Time:Update()
        world:Update()
	

        world:Render()
		context:DrawStats(10, 10)
        context:Sync(false)
   collectgarbage()
end

This is a simple example, where the memory goes up. Lua Script.

  • Thanks 1

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

 

6 minutes ago, Josh said:

I'm using the default branch, not the beta build.

https://www.ultraengine.com/community/applications/core/interface/file/attachment.php?id=19023&key=ed9d8c7437710a1384bbc3b62955f7fd

 

AstrocucoX.rarI don't know what I'm doing wrong, see this is the example, when I press the escape key, everything goes up in ram memory usage in an uncontrolled way. 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

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