From 62b8cc388e7bcfd405efd1708f2149dcb252baae Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 16 Sep 2017 14:34:54 +1000 Subject: [PATCH] spawnfuncs: fix SV_OnEntityPreSpawnFunction --- qcsrc/lib/_all.inc | 3 ++- qcsrc/lib/spawnfunc.qh | 10 +++++++++- qcsrc/server/sv_main.qc | 3 --- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 9d5820910..d44c5e89c 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -241,7 +241,8 @@ void make_safe_for_remove(entity this); void SV_OnEntityPreSpawnFunction() { ENGINE_EVENT(); - if (_SV_OnEntityPreSpawnFunction) _SV_OnEntityPreSpawnFunction(this); + __spawnfunc_expecting = true; + __spawnfunc_expect = this; } #define SV_OnEntityPreSpawnFunction _SV_OnEntityPreSpawnFunction diff --git a/qcsrc/lib/spawnfunc.qh b/qcsrc/lib/spawnfunc.qh index 4638bca2d..f1eb477a0 100644 --- a/qcsrc/lib/spawnfunc.qh +++ b/qcsrc/lib/spawnfunc.qh @@ -57,7 +57,9 @@ noref bool require_spawnfunc_prefix; g_map_entities = IL_NEW(); \ IL_EACH(g_spawn_queue, true, __spawnfunc_spawn(it)); \ MACRO_END - +#ifdef SVQC + void _SV_OnEntityPreSpawnFunction(entity this); +#endif void __spawnfunc_spawn(entity prototype) { entity e = new(clone); @@ -66,6 +68,12 @@ noref bool require_spawnfunc_prefix; #define X(T, fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; } SPAWNFUNC_INTERNAL_FIELDS(X); #undef X +#ifdef SVQC + _SV_OnEntityPreSpawnFunction(e); + if (wasfreed(e)) { + return; + } +#endif e.__spawnfunc_constructor(e); } diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 68e7b375b..18706028f 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -320,8 +320,6 @@ bool expr_evaluate(string s) void SV_OnEntityPreSpawnFunction(entity this) { - __spawnfunc_expecting = true; - __spawnfunc_expect = this; if (this) if (this.gametypefilter != "") if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, this.gametypefilter)) @@ -363,7 +361,6 @@ void SV_OnEntityPreSpawnFunction(entity this) return; LABEL(cleanup) builtin_remove(this); - __spawnfunc_expecting = false; } void WarpZone_PostInitialize_Callback() -- 2.39.2