View Issue Details

IDProjectCategoryView StatusLast Update
0005845The Dark ModCodingpublic25.06.2022 11:05
Reporterjoebarnin Assigned ToDragofer  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOS10 
Product VersionTDM 2.09 
Target VersionTDM 2.11Fixed in VersionTDM 2.11 
Summary0005845: TDM crashes when restoring a save done soon after killing an elemental
DescriptionKill an elemental (in this case, atdm:ai_elemental_blue), and then do a quicksave within a few seconds (4 seconds or so). Now, try to load that quicksave. TDM crashes to the desktop.
If you wait approximately 5-6 seconds (or longer) after killing the elemental, and then do the save, you can safely load that save, no crash.
Steps To ReproduceInstall the attached map. Start the mission, choose "Objectives", then "Buy Equipment", then "Start Mission". You are in a room with a blue elemental. Equip a water arrow and shoot the elemental - it will die. Within 4 seconds, do a quicksave. Now, do a quickload - TDM will crash to the desktop. If you start TDM and try to load the quicksave again, you'll crash again.

Start the mission again, kill the elemental, and this time wait a bit longer before saving (6 seconds or so). Now you'll be able to load the save without a crash.
Additional InformationI tried this on 2.10 (#9648) and it crashed too.

For your information: I originally tested this bug by creating crash.map in an existing mission, and tested it using "dmap crash" and "map crash". I saw the same behavior, crash to desktop. I then put crash.map into it's own .pk4, for delivery to you, and it still crashes.
TagsNo tags attached.

Activities

joebarnin

joebarnin

17.12.2021 23:10

reporter  

crash.pk4 (5,458 bytes)
stgatilov

stgatilov

27.12.2021 13:23

administrator   ~0014611

Last edited: 27.12.2021 13:23

This is caused by mismatch in num == bodies.Num() in idPhysics_AF::Restore.

There is some hack called "m_NumOrigBodies" added back in 2007 by @ishtvan (rev 1421):
    /**
    * TDM: Number of _original_ bodies from the loaded AF file
    * We need this to implement a hack where added bodies aren't saved/loaded,
    * because they will be added again from scratch on restore.
    * We must do this because Id chose to re-load the AFs instead of restore them
    **/
    int m_NumOrigBodies;
    /**
    * Number of original constraints loaded from this entity's AF file
    **/
    int m_NumOrigConstraints;
Which is supposedly reference here:
  https://forums.thedarkmod.com/index.php?/topic/6248-saving-and-loading/&do=findComment&comment=127049

I'd say that his workaround should better be removed, and we should try to solve the problem properly.
stgatilov

stgatilov

27.12.2021 13:58

administrator   ~0014612

Last edited: 27.12.2021 14:02

Ok, the problem happens because idAF::Load fails to restore with the following console warning:
  idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no or defaulted modelDef '%s'
Of course, nobody has seen it because the execution continues and crashes shortly after that.

This happens because animator->ModelDef() is NULL after restoring.
So, when game is saved, its animator saves null modelDef.

ModelDef is NULL because it is reset when elemental dies.
Since it has "model_death" spawnarg, idAI::Killed calls SetModel with some particle model as argument.
idAnimator::SetModel clears the old modelDef, and but does not set a new one because particle model (modelname = "imp_explosion_blue.prt") is not a valid modelDef:
    modelDef = static_cast<const idDeclModelDef *>( declManager->FindType( DECL_MODELDEF, modelname, false ) );
    if ( !modelDef ) {
        return NULL;
    }

It seems that for animated entity, one can only SetModel a modelDef.
stgatilov

stgatilov

28.12.2021 05:31

administrator   ~0014619

I guess this is not so easy to fix.

First of all, I'd like to apply the provided patch: it forbids changing model of animated entity to something which is not a modelDef.
However, before doing this:
  1) One has to reimplement death animation of elemental.
     I'd say it should die immediately, spawning a particle entity to be removed a few seconds after.
     My attempt was blocked by a dangling thread "rand_osc", which survives after its light is dead (not sure how it is supposed to be terminated).
  2) There are two missions which have forked elemental defs, and they must be updated too.
AnimatedSetModelModelDef.patch (1,238 bytes)   
Index: game/AFEntity.cpp
===================================================================
--- game/AFEntity.cpp	(revision 9755)
+++ game/AFEntity.cpp	(working copy)
@@ -1331,6 +1331,21 @@
 }
 
 /*
+================
+idAFEntity_Base::SetModel
+================
+*/
+void idAFEntity_Base::SetModel( const char *modelname ) {
+	idAnimatedEntity::SetModel(modelname);
+
+	if ( !GetAnimator()->ModelDef() ) {
+		//stgatilov #5845: can only switch AF model with compatible AF model
+		//because we don't (and cannot) change the body set in af.physicsObj
+		common->Error("idAFEntity_Base::SetModel: model %s is not modelDef", modelname);
+	}
+}
+
+/*
 ===============
 idAFEntity_Base::ShowEditingDialog
 ===============
Index: game/AFEntity.h
===================================================================
--- game/AFEntity.h	(revision 9755)
+++ game/AFEntity.h	(working copy)
@@ -221,6 +221,7 @@
 	virtual bool			GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
 	virtual bool			UpdateAnimationControllers( void );
 	virtual void			FreeModelDef( void );
+	virtual void			SetModel( const char *modelname ) override;
 
 	virtual bool			LoadAF( void );
 	bool					IsActiveAF( void ) const { return af.IsActive(); }
AnimatedSetModelModelDef.patch (1,238 bytes)   
Dragofer

Dragofer

22.05.2022 11:47

developer   ~0014837

Reimplemented death animation by emitting the particle in the world, independently of the elemental entity. Rev 16488.
The fix for FMs with forked elemental defs is still pending as laid out here: https://forums.thedarkmod.com/index.php?/topic/21425-5845-elemental-death-animation/&do=findComment&comment=473898
stgatilov

stgatilov

11.06.2022 18:42

administrator   ~0014863

Last edited: 11.06.2022 19:05

I applied the patch to SVN (rev 9931).

Also, I see now that there are three missions with custom elemental def:
  Black Mage (defined ai_elemental_special is not used, both blue and fire elementals are core ones)
  Painter's Wife
  By Any Other Name (can't find any usage of elemental def)
stgatilov

stgatilov

25.06.2022 11:04

administrator   ~0014921

Bikerdude wrote:
---------------------------------------
  1) removing the blue elemental .def file
  2) bumping the "Required version" in darkmod.txt to 2.09
The blue elementals works as expected.
---------------------------------------

So I'm closing this.

Issue History

Date Modified Username Field Change
17.12.2021 23:10 joebarnin New Issue
17.12.2021 23:10 joebarnin File Added: crash.pk4
27.12.2021 13:23 stgatilov Note Added: 0014611
27.12.2021 13:23 stgatilov Note Edited: 0014611
27.12.2021 13:58 stgatilov Note Added: 0014612
27.12.2021 14:02 stgatilov Note Edited: 0014612
28.12.2021 05:31 stgatilov Note Added: 0014619
28.12.2021 05:31 stgatilov File Added: AnimatedSetModelModelDef.patch
28.12.2021 05:31 stgatilov Target Version => TDM 2.11
28.12.2021 05:31 stgatilov Description Updated
28.12.2021 05:31 stgatilov Steps to Reproduce Updated
28.12.2021 05:31 stgatilov Additional Information Updated
22.05.2022 11:47 Dragofer Note Added: 0014837
11.06.2022 18:42 stgatilov Note Added: 0014863
11.06.2022 18:49 stgatilov Note Edited: 0014863
11.06.2022 19:05 stgatilov Note Edited: 0014863
25.06.2022 11:04 stgatilov Note Added: 0014921
25.06.2022 11:05 stgatilov Assigned To => Dragofer
25.06.2022 11:05 stgatilov Status new => resolved
25.06.2022 11:05 stgatilov Resolution open => fixed
25.06.2022 11:05 stgatilov Fixed in Version => TDM 2.11