About Store Forum Documentation Contact



Post Reply 
Destructible seldomly crash the game after broke it to pieces then remove them
Author Message
KrysleQuinsen Offline
Member

Post: #1
Destructible seldomly crash the game after broke it to pieces then remove them
On binary build, I found that Destructible can crash the game once it breaks to pieces then remove the object (either clear() or return false)

Tested with a tutorial but instead preplaced destructible object to the worlds and DestruchMesh is in the class itself. It crashes about ~10% of the time, so might have to try for a while. Seems to crash on both Breakable and Static Mode.

Project File
https://www.dropbox.com/scl/fi/9onbeec98...ghod9&dl=0

Code:
class Destructible : Game.Destructible
{
   DestructMesh destruct;
   virtual bool update()
   {
      if(Kb.bp(KB_NPENTER)) return false;
      return super.update();
   }
   virtual void setUnsavedParams()
   {
      destruct_mesh=&destruct;
      super.setUnsavedParams();
   }
   virtual void create(Object &obj)
   {
      if(obj.mesh()) destruct.create(*obj.mesh(), 24, UID(2519161163, 1078307672, 184317862, 2816697732), 1, 320);
      super.create(obj);

   }
}
Game.ObjMap<Destructible> Destructibles;

void InitPre()
{
   INIT();
   Ms.hide();
   Ms.clip(null, 1);

   Physics.create();

   Cam.dist =10;
   Cam.yaw  =-PI_4;
   Cam.pitch=-0.5;
   Cam.at.set(16, 0, 16);
}

bool Init()
{
   // load world
   Game.World.activeRange(D.viewRange())
             .setObjType(Destructibles, OBJ_DESTRUCTIBLE)
             .New(UID(2374084413, 1147719251, 1481930149, 1042065803));
   if(Game.World.settings().environment)Game.World.settings().environment->set();
   return true;
}

void Shut()
{
   Game.World.del();
}

bool Update()
{
   if(Kb.bp(KB_ESC))return false;

   Cam.transformByMouse(0.01, 10, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
   Game.World.update(Cam.at);

   if(Kb.bp(KB_SPACE))
   {
      REPA(Destructibles) // now adjust velocities to all objects
      {
         Destructible &d=Destructibles[i];
         REPAO(d.actors).vel(Random(Ball(12)));
      }
   }
   return true;
}

void Render()
{
   Game.World.draw();
}
void Draw()
{
   Renderer(Render);
   if(Kb.b(KB_LCTRL))
   {
      Renderer.setDepthForDebugDrawing();
      Physics.draw();
   }
   D.text(0, 0.9, "Press Space to Explode NPEnter to delete");
}

Call stack when it crashed.
Code:
    Application.exe!EE::_Memx::validIndex(void const *)    C++
    Application.exe!EE::_Cache::lockedRemoveData(void const *,bool)    C++
    Application.exe!EE::_Cache::decRef(void const *)    C++
    Application.exe!EE::Game::Destructible::~Destructible(void)    C++
    Application.exe!Destructible::~Destructible()    C++
    Application.exe!EE::Map<EE::UID,Destructible>::Elm::~Elm()    C++
    Application.exe!EE::Map<EE::UID,Destructible>::Elm::`scalar deleting destructor'(unsigned int)    C++
>    Application.exe!EE::ClassFunc<EE::Map<EE::UID,Destructible>::Elm>::Del(void * elm) Line 220    C++
    [External Code]    
    Application.exe!EE::Map<EE::UID,Destructible>::clear() Line 1881    C++
    Application.exe!EE::Game::ObjMap<Destructible>::clear() Line 2053    C++
    Application.exe!Update() Line 44    C++
    [External Code]
(This post was last modified: 06-10-2024 08:19 AM by KrysleQuinsen.)
06-10-2024 08:16 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Destructible seldomly crash the game after broke it to pieces then remove them
I ran the project many times
press space
press enter

but never crashed.

Please make sure you're using latest version from source/github as there were some bugfixes.
06-10-2024 08:58 AM
Find all posts by this user Quote this message in a reply
KrysleQuinsen Offline
Member

Post: #3
RE: Destructible seldomly crash the game after broke it to pieces then remove them
I updated my EE to source build (it's another account) but the crash still happens.
Usually press Space Bar then wait for a couple of seconds for the pieces to slow down or almost all stop then press NPEnter.

I also tried with EE debug version but it still gives the same call stack plus a couple of private-only section.
Code:
>    Application.exe!EE::_Memx::elmIndex(const void * elm) Line 19    C++
    Application.exe!EE::_Memx::validIndex(const void * elm) Line 298    C++
    Application.exe!EE::_Memx::contains(const void * elm) Line 52    C++
    Application.exe!EE::Memx<EE::_Cache::Elm>::contains(const EE::_Cache::Elm * elm) Line 1211    C++
    Application.exe!EE::_Cache::lockedContains(const EE::_Cache::Elm * elm) Line 72    C++
    Application.exe!EE::_Cache::lockedRemoveData(const void * data, bool counted) Line 445    C++
    Application.exe!EE::_Cache::removeData(const void * data, bool counted) Line 509    C++
    Application.exe!EE::_Cache::decRef(const void * data) Line 525    C++
06-10-2024 03:52 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Destructible seldomly crash the game after broke it to pieces then remove them
I've reproduced the crash now, after running everything in Debug.
Checking now..
06-11-2024 06:10 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: Destructible seldomly crash the game after broke it to pieces then remove them
The crash is because you create DestructMesh destruct; as class object.
But when destructible is broken into pieces, then the pieces reference that 'destruct'.
But in the case when the owner of DestructMesh destruct gets deleted first, then there are still remaining pieces that reference the deleted 'destruct'.
So you should keep the 'destruct' somewhere outside the class, so all pieces can still access it, no matter which one gets deleted first.
06-11-2024 06:19 AM
Find all posts by this user Quote this message in a reply
KrysleQuinsen Offline
Member

Post: #6
RE: Destructible seldomly crash the game after broke it to pieces then remove them
Thank you for the insight, my current solution is the make a Memx of a new class that has DestructMesh and optionally Reference<Destructible> that removes itself when they are invalid.
06-11-2024 08:11 AM
Find all posts by this user Quote this message in a reply
Post Reply