Mitigate ED_Alloc crashes caused by disposable entity accumulation - #1188
Mitigate ED_Alloc crashes caused by disposable entity accumulation#1188lozatto wants to merge 6 commits into
Conversation
Feature/hud message queue
|
I don't see the point on this, if you're having crashes with max edicts I think the issue is your mod instead of this solution. |
I agree that a mod creating entities indefinitely should be fixed at the source, and I don't intend this GC to replace fixing entity leaks in mods. However, I think there is still a valid purpose for having this protection in the GameDLL. The problem with max edicts is that once the engine reaches the limit, the failure happens at allocation time. At that point, there is no opportunity for the GameDLL to recover unless it has already reclaimed some disposable entities. This GC is intentionally proactive. It does not wait until So I see this as a defensive/resource-reclamation mechanism rather than a workaround for broken mods. I also agree with your point that this alone cannot guarantee that Because of that, I think the ideal solution is actually two layers:
The first layer reduces the probability of reaching the limit, while the second layer is the actual last line of defense. Regarding I also agree that logging when entity usage reaches the critical threshold would be useful. In fact, I think the GC could log the current entity count, max edicts, how many entities were reclaimed, and potentially which classes are consuming the edicts. That would make this useful not only as a safeguard but also as a diagnostic tool. So I don't intend to claim that this prevents every possible If you think the allocation failure handling should also be addressed in the same area, I'm open to extending the patch in that direction. |
There is also another scenario worth considering: reaching the edict limit does not necessarily mean that the mod is leaking entities. For example, I can have a very aggressive Boss encounter where, during a specific attack phase, the Boss legitimately creates a large number of temporary entities at once. The server may already be close to the edict limit because of normal gameplay, and that burst can push it over the limit. In that case, there may be no persistent entity leak to fix. The problem is simply that the server temporarily reaches the allocation limit. This is another reason why I think proactive garbage collection has value in the GameDLL. If there are disposable entities such as old So I see two different cases:
The GC is not intended to hide the first problem. It is intended to make the second case safer, while also reducing the impact of accumulated disposable entities. And I agree that allocation itself should still fail gracefully if there is genuinely no edict available. That would be the final safety net. |
|
My point is, I have an active server (mostly +20 users 32 at night) on some maps where bosses spawns a bunch of entities (explosives-effects) and/or children (lesser npc's) and I haven't had an issue with maxedicts error. |
Yeah, I agree. I think this part would make more sense to be addressed in ReHLDS, since ED_Alloc() is an engine-level allocation function. However, I think it would still be beneficial to keep both layers of protection. The engine could handle max_edicts exhaustion gracefully by returning nullptr instead of crashing, while ReGameDLL can still check the available edicts before attempting the allocation and validate the returned entity afterward. So it would essentially be a double safety layer:
I don't see these as competing solutions. The ReHLDS change would make the engine more robust, while keeping the checks in ReGameDLL protects the mod from unexpected allocation failures. This also covers legitimate peak-usage scenarios, such as a boss spawning several effects/projectiles/child NPCs in a short burst while the server is already close to the edict limit, without requiring us to assume that every max_edicts condition is caused by an entity leak or a bug in the mod. |
This PR introduces an intelligent Garbage Collector to prevent the notorious ED_Alloc: no free edicts server crash.
In heavy mods like Zombie Plague or servers with high drop rates, the engine can easily hit the entity limit due to excessive dropped weapons, shields, and gibs on the ground. When that happens, the server crashes instantly.
What this does:
mp_entity_gc(enabled by default) to control the system.StartFrame.weaponbox,weapon_shield, andgib) to free up slots.This is a massive stability improvement for custom and heavily modded servers!