Jump to content
  • 0

Question about Disposed Entities


Lathander

Question

Hopefully this is a quick question. While working on some NPC logic, I noticed that entities (npcs) once dead are marked as dead and disposed but do not get wiped from memory.. am I seeing this wrong? I had a npc hell bent on killing an invisible entity that was already dead, and looks to be that the dead logic was still running after doing a console print check. If that is the case, how long do those objects remain around? Is there a garbage collector or some script somewhere that cleans up dead / disposed entities on the server, or am I missing something?

 

Thanks.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

"while working on some NPC logic"

 

So there are modifications, that begs the question, how extensively modified? Can this be reproduced on stock intersect? Is the dead NPC still in the NPC list, or just the living NPC has a reference to the dead one still? Both issues are the NPC sticking around, but they're not the same

 

And without knowing what you changed we have no idea if the NPC is sticking around because its death logic hasn't finished running, or because you introduced a bug

 

 

Link to comment
Share on other sites

  • 0

Yes there are modifications, many. I'm certain I could reproduce it on the stock intersect build. The dead npc is in fact removed from the entity list on the map as that has remained unchanged. The death code just checks isDead and returns. All entities pass through this logic for death and dispose. The only reason I discovered that the script was simply marked as disposed is because during npc movement logic for some reason the npc never clears its target, or tempTarget, I forget which. My modifications to the npc code simply allowed me to see that the npc object was still active in memory (as it was still targeted by another npc) only disposed.

 

I am guessing there is a garbage collector that clears the disposed objects, but I just wanted to know for certain if anyone could shed light on that. The problem is not that my modifications allowed me to see it, it is more so me wanting to understand the memory allocation / disposal mechanics.

 

But to answer your questions. No in this matter it is not a bug, and no, the death logic completed fully. Appreciate the reply otherwise :)

Link to comment
Share on other sites

  • 0
19 hours ago, Lathander said:

npc never clears its target

Yeah, you're right, that targets are never untargetted.

Panda, analyzed what you said and sent a fix which you can find here:

https://github.com/AscensionGameDev/Intersect-Engine/pull/1405

 

Thank you for your contribution, we hope to have more suggestions from you in the future.

Link to comment
Share on other sites

  • 0
1 hour ago, Lathander said:

Glad to see my inquiry led to a fix, still in the dark about garbage collection, but based on googling guessing its .net GC. Wondering if it has been optimized for the server at all.


It would have been beneficial for a bug with repro steps to have been opened on the Github repo, as it stands my PR was just a basic change that I think will have fixed it but I can't guarantee it.


On the topic of garbage collectors, we are running .NET Framework on main and so we are locked into the .NET Garbage Collector. There are apparently some configuration options we can tweak even in .NET Framework, but none of those configuration options would have fixed this issue (and garbage collection is not even something useful for us to configure yet, the rest of the codebase is not performant enough for it to yield real benefits that wouldn't otherwise be gained by simply fixing the code). As far as I am aware, the .NET Garbage Collector, or any Garbage Collector for that matter, will only trim orphaned structures in memory; in other words ones that no longer have a reference. Our custom marking of an entity as disposed is nothing more than just saying "don't use this anymore" to our own code, but it doesn't trigger any sort of garbage collection.

Assuming that the "Target" property was the only remaining reference per your description, my fix of just clearing the property value will allow the GC to collect it whenever it deems fit to run.

Link to comment
Share on other sites

  • 0

Thanks for the color panda, that is very helpful and I appreciate your thoughtful reply. It was a little difficult for me to articulate the way to reproduce the issue, as I only discovered it because I was using the npc target logic to determine a target for a (pet)player-owned-instance of an npc. It was only by using this pet npc, and seeing that it was still casting spells into blank spaces that I realized.. oh you still have an active target on an entity I thought was dead/disposed...

 

This raises a question for you, and perhaps for a future consideration.. but instead of disposing the entity after it is marked as dead, couldn't it be marked for respawn, instead of the respawning process creating an entirely new entity? That way, it wouldn't create garbage collection. Just teleport the entity to the spawn location once respawn timer is up, reset stats, and begin the process a new. Obviously this wouldn't work for event created npcs, but it would work for ones that are loaded to the map as spawns.

Link to comment
Share on other sites

  • 0
2 hours ago, Lathander said:

Thanks for the color panda, that is very helpful and I appreciate your thoughtful reply. It was a little difficult for me to articulate the way to reproduce the issue, as I only discovered it because I was using the npc target logic to determine a target for a (pet)player-owned-instance of an npc. It was only by using this pet npc, and seeing that it was still casting spells into blank spaces that I realized.. oh you still have an active target on an entity I thought was dead/disposed...

 

This raises a question for you, and perhaps for a future consideration.. but instead of disposing the entity after it is marked as dead, couldn't it be marked for respawn, instead of the respawning process creating an entirely new entity? That way, it wouldn't create garbage collection. Just teleport the entity to the spawn location once respawn timer is up, reset stats, and begin the process a new. Obviously this wouldn't work for event created npcs, but it would work for ones that are loaded to the map as spawns.

I saw a 3d rpg that used this, a class had the ability to detect monsters on the map, so on the mini map appeared the red dots for each monster, after killing them all, the points remained on the map, and when they were born they started moving again, they didn't were they excluded from the map, were they just invisible and perhaps intangible? but it's interesting

Link to comment
Share on other sites

  • 0
4 hours ago, Lathander said:

This raises a question for you, and perhaps for a future consideration.. but instead of disposing the entity after it is marked as dead, couldn't it be marked for respawn, instead of the respawning process creating an entirely new entity? That way, it wouldn't create garbage collection. Just teleport the entity to the spawn location once respawn timer is up, reset stats, and begin the process a new. Obviously this wouldn't work for event created npcs, but it would work for ones that are loaded to the map as spawns.


Well since moving to a generic ECS is our target, I'm not sure how useful a specialized system like this will be long term. I think it will probably still be possible after that move, but it's too bug-prone of a feature to include in our code base right now.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...