Page 1 of 1

Freeze when using idfa (et al) in a portal test map

PostPosted: Sun Jan 14, 2018 10:05 am
by boris
So I've got this simple sector portal test map, and for some reason it freezes GZDoom when using the idfa or idkfa cheat, or use the "give" command, like "give bfg9000".

Map is attached.

Using gzdoom-g3.3pre-278-ge8a7f00 (but it also happened in earlier versions).

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Mon Jan 29, 2018 10:08 am
by Shrinker
My analysis so far...
Code: Select allExpand view
"give bfg9000" in that map freezes the game. I can reproduce the error.
c_dispatch.cpp
   if ( (com = FindNameInHashTable (Commands, beg, len)) )
c_cmds.cpp
   CCMD (give)
   DEM_GIVECHEAT
d_net.cpp
   case DEM_GIVECHEAT
m_cheat.cpp
   void cht_Give (player_t *player, const char *name, int amount)
   VMCall(func, params, 3, nullptr, 0);
   IFVIRTUALPTR leads me to script functions
   the function "CheatGive" is called
so that might be in... player_cheat.txt
   GiveInventory...
   setting breakpoints on all giveInventory-s I can find, I land in:
p_mobj.cpp/bool AActor::GiveInventory(PClassActor *type, int amount, bool givecheat)
   item = static_cast<AInventory *>(Spawn (type, Pos(), NO_REPLACE));
   if (item == NULL) return false; => item is not null in our case, so the spawning worked
   ...
   if (!item->CallTryPickup (this)) => ### this freezes ###
      bool AInventory::CallTryPickup(AActor *toucher, AActor **toucher_return)
      if (func == nullptr) PClass::FindFunction(&func, NAME_Inventory, NAME_CallTryPickup);
      VMCall(func, params, 2, ret, 2); => back to the scripting layer
      we probably land in:
inventory.txt/bool, Actor CallTryPickup(Actor toucher)
   what about CanPickup? => determins if the player is allowed to pick it up
   what about TryPickup?
   hm... I can't figure it out further from here.
When I stop the frozen program in the debugger, I end up with a program stack that doesn't allow me to find my way back into the known source code...
I don't know how to push changed files from the zscript dir into the program -- The scripting part is so involved here it would help a lot to comment out a things a bit to pin down the fault location further.
Oh wait, I've continued and stopped the debugger a few more times and landed somewhere!
p_mobj.cpp/AActor *AActor::StaticSpawn (PClassActor *type, const DVector3 &pos, replace_t allowreplacement, bool SpawningMapThing)
   => P_FindFloorCeilingz
   while ((mit.Next(&cres)))
   {
      PIT_FindFloorCeiling(mit, cres, mit.Box(), tmf, flags|cres.portalflags);
   }
   This thing loops infinitely!


Okay so... I'm looking at your map in the editor, and my repro map from here is quite similar: viewtopic.php?f=2&t=58193
Only there's a main difference: Your portal marker wall segments also double as real wall segments. That might be wrong!
This is how I've done it, following an example map I got from somewhere else: https://imgur.com/a/Q6opv

Regarding the code I've found:
Maybe there should be a guard checking if the first "cres" is visited again on the way or something like that, or maybe this is really an error in the level design that should somehow be caught earlier on...

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Mon Jan 29, 2018 10:39 am
by Graf Zahl
The problem with this map is actually quite simple: Any inventory item to be given is spawned at (0,0), but when trying to determine its position with regards to the portal it ends up in the lower part again after relocation because the two sectors are too close together. This results in an endless attempt to find the upper part, always ending up in the lower part.

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Mon Jan 29, 2018 1:07 pm
by Shrinker
So would a workaround be to place a simple room around the 0, 0 location?

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Mon Jan 29, 2018 1:09 pm
by Graf Zahl
The best workaround would be to keep portal areas further apart with some separating geometry in between. These problems happen because a spot outside valid geometry ends up in a portal sector.

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Sun Feb 25, 2018 9:15 am
by Gez
What about simply giving such items (spawned to immediately go in an inventory instead of spawned to be placed on the map) a flag that excludes them from any portal check?

Re: Freeze when using idfa (et al) in a portal test map

PostPosted: Sun Feb 25, 2018 9:18 am
by Graf Zahl
That wouldn't have fixed the actual issue, which was that the portal code never checked if an actor somehow ended up in the wrong portal group after relocation.