Jump to content

FreeEntity()


Marleys Ghost
 Share

Recommended Posts

What exactly does FreeEntity() free on an Entity?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Only god knows ( that's Josh :)

 

But I would be very surprised if it didn't decrement the usage counter

of all its used resources (textures etc) and same for all its child entities.

 

The decrement of the usage counter is also just a guess, but somehow there must

exist such a mechanism so a resource can be used by many entities. The resource

will the be removed from memory when its usage counter becomes 0.

 

Much guessing here :)

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

Yeah thats what I would think, but I cant confirm this to be the case for the LOD's of a particular model .. even when the main models usage count is zero. If I load a model, say 10 times, 10 different instances of the same model, then freed all 10 then I assumed that all references to that models main model and LOD's , textures/materials would be deleted. Thus when loading a new instance of that model the system would have to reload all again as there would be no cached instance of it or its LOD's, Textures or Materials.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Well, after an hour of testing I dont think FreeEntity() free's an entity entirely, its more FreeALittleOfTheEntity() :blink:

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Sounds most unreliable. So thats another way to say that there is no working. FreeEntity :-S

 

 

I have to concur, either that or it does not work how we expect it to which leaves the question, how do you truly free and Entity?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

It removes the entity from the global lists, and may do other specific things depending on the entity type. The garbage collector will automatically delete the memory allocated for it.

 

You might be able to still call some commands on a freed entity, but you definitely should not.

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

When you do a FreeEntity() just set the entity pointer to NULL after that, then you don't accidentally and incidentally do anything more with the entity. LEO does that automatically already, and LEO should be used in first place anyway, or even GameLib which uses LEO also.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

It removes the entity from the global lists, and may do other specific things depending on the entity type. The garbage collector will automatically delete the memory allocated for it.

 

You might be able to still call some commands on a freed entity, but you definitely should not.

 

 

Morning Josh, what I am trying to do is remove all traces of a loaded model, that is the main model, the LOD's and textures/materials from memory I thought that was what EntityFree() would do. Is there a way to force the removal of a model, the LOD's and textures/materials from memory so when its reloaded it has to reload everything as though it was the first time?

 

 

When you do a FreeEntity() just set the entity pointer to NULL after that, then you don't accidentally and incidentally do anything more with the entity. LEO does that automatically already, and LEO should be used in first place anyway, or even GameLib which uses LEO also.

 

 

What has that to do with the issue I am explaining?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Try setting the pointers to NULL after freeing them and then force a garbage collection (GarbageCollect()??)

 

If you have a console window open so you can observe resources coming and going you might observe that the process of freeing up testures/sounds is not instant. Is it possible you might have a situation where a reference count is incorrect and so the garbage collector isn't dumping like it should?

 

I know FreeEntity() works as I expect it to with 2.42 but I don't do anything too fancy with LODS and models. When I used FreeEntity() on vehicles I want removed from the game world they do vanish. Although the textures can take a few seconds or longer to announce they have been removed from the system.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Morning Flex m8, setting the pointer to null after freeing and forcing a garbage collection were two of the things I tried first, made no difference.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

This issue really has nothing to do with garbage collection or setting something to null. From my test of MG's problem, there is an issue with freeing items from memory when there are LODs involved.

 

If I load a model that has 6 LODs and free the model when i am looking at the main mesh, it will show in the log that the main mesh, the model reference, and all of the LOD meshes are being deleted.

 

If I load a model that has 6 LODs and free the model when i am looking at LOD2, it will show in the log that only LOD2, the model reference, and LOD meshes 3 thru 6 are being deleted. But the main mesh and the LOD1 mesh are not. And I can verify that if i load the model again as it will only load the items that were deleted.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Oh my, that makes sense. I'm going to try this myself. Typically I'm only freeing entities that are in view.

 

Little edit..

 

I take it then that the entity reference being freed is perhaps not the top level parent? TModel being the container for all the LOD meshes and body.

 

I just checked my code to confirm I'm Freeing the top level TModel, regardless of it being within the view volume with LOD1 visible (my M1A1 tank model has LOD0, LOD1, LOD2, LOD3). So I can't easily replicate this quickly.

 

My TModel reference comes from calling GetMeshModel() with a pick result, this ALWAYS goes to the top of the model hierarchy.

 


' DO SOME PICK HERE THEN FETCH THE TMODEL ENTITY '
' AFTER CHECKING FOR NULLS ALWAYS '
Local model:TEntity = GetMeshModel(hitpick.entity)


Function GetMeshModel:TEntity(entity:TEntity)
Local cName:String
While entity
	cName = GetEntityKey(entity, "class")
	If cName = "Model"
		Return entity
	End If
	If entity.parent Then
		entity = GetParent(entity)
	Else
		Return Null
	End If
Wend
End Function

Edited by Flexman

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Well after more testing, as far as I can tell FreeEntity is a misnomer, it certainly does not free the entity with all its associated "baggage", just a some of it.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Well after more testing, as far as I can tell FreeEntity is a misnomer, it certainly does not free the entity with all its associated "baggage", just a some of it.

To bad. This makes load new scenes a bit hard to do.

After a some new scene loads it will lead to having a bunch of non-used memory block allocated.

 

Of course one must be sure to have free'd up all resources (except the player maybe) between scenes.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

To bad. This makes load new scenes a bit hard to do.

After a some new scene loads it will lead to having a bunch of non-used memory block allocated.

 

Of course one must be sure to have free'd up all resources (except the player maybe) between scenes.

 

 

True, but then I was (I am no longer) under the impression this was all dealt with using FreeEntity ...

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Models and textures will be freed when they are no longer in use. If they aren't being freed you have another model or material or something in use that has not been freed.

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

In Marley's example it is only a single model being loaded and deleted. However, as he's reporting, not all of the LOD's are being free'd, which is opposite of what is expected, and is a bug that needs to be investigated. It's basically memory leaking. As you'd have LOD's still within memory and no way to actually access them and they're never free'd (until the application is terminated, which has to be tested too, but it should be).

Link to comment
Share on other sites

There is really no such thing as a scene. A scene is split on load time into 3 worlds, so you have to scan all 3 worlds and delete all entities from them. Some entities are not part of any worlds, that's why I had make a special loader for those entities in gamelib also, to be able to access and free all entities. For examples sources are loaded outside of all worlds and it's up to you to register them in your C++ entity maps.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

The easiest and most common way is just to use ClearWorld() on all 3 worlds, and then recreate the player again. However, in near future when gamelib starts to use SQL databases instead of sbx scenes, there will be no use for ClearWorld() anymore, since all models will have to be loaded and deleted continuosly. So there is really no more level loading, but it's just one infinite database which is streamed.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Models and textures will be freed when they are no longer in use. If they aren't being freed you have another model or material or something in use that has not been freed.

 

 

I appreciate what it is you are saying , but still it appears FreeEntity() is not freeing everything thats loaded for a particular model, specifically all lOD's.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

This is one of the many small apps I have used to test this.

 

Download and Extract, you will have two folders LOD and Test Model Large, open LOD and run the LOD.exe, this loads a single model Box.gmf from the LOD\Test Model\ folder which is in the App dir. Hold down the RMB for camera view and move in and out. Box.gmf has 6 LOD's which are basically different colours, now with the App still running, navigate to the Test Model Large folder, in which are 7 .gmf's identically named to those in LOD\Test Model\, which are also cubes only bigger, copy and paste those into the LOD\Test Model\ folder overwriting the files it contains. going back to the App, press the F key to free the Entity, pressing the L key will load the Box again, only using the new files, or it should.

 

The models in the LOD\Test Model\ directory can be reset to the originals by extracting the contents of the Test Model.rar to that directory.

 

 

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

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