View Issue Details

IDProjectCategoryView StatusLast Update
0005845The Dark ModCodingpublic01.08.2022 20:30
Reporterjoebarnin Assigned ToDragofer  
Status resolvedResolutionfixed 
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 in an existing mission, and tested it using "dmap crash" and "map crash". I saw the same behavior, crash to desktop. I then put into it's own .pk4, for delivery to you, and it still crashes.
TagsNo tags attached.




17.12.2021 23:10


crash.pk4 (5,458 bytes)


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:

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


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.


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 @@
+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);
+	}
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)   


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:


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)


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.


01.08.2022 19:59

administrator   ~0015111

Last edited: 01.08.2022 20:19

It seems that two missions now get the error, trying to setModel something different from modelDef on animated entity:

In antr, there is e.g. func_static_1266:
"classname" "atdm:ambient_head_3"
"name" "func_static_1266"
"model" "models/md5/chars/heads/npcs/female01_shaggy.md5mesh"
"origin" "6329.55 -1615.39 -1194.89"
"rotation" "-1.11022e-16 -1 1.11022e-16 -1 1.11022e-16 1.11022e-16 -1.11022e-16 -1.11022e-16 -1"
"snd_bounce" "tdm_impact_fish"
This is a scene where woman has no head...
When I look at the woman, I get per-frame spam of warnings related to dynamic model...

In ch1_eaton, there is e.g. fog1:
"classname" "func_animate"
"name" "fog1"
"angle" "1.066956"
"model" "ea001_etherfog_low.prt"
"origin" "2524.77 1097.17 -460"
"wait" "5"
No idea what it means: in-game I don't see anything special except for animated trees ta this position.


01.08.2022 20:30

administrator   ~0015112

Ok, I committed a fix in svn rev 10061.
I limited the condition for error.

Now the error happens if both conditions are true:
  1) new model is not a modelDef
  2) there was a modelDef previously attached
Now the two mentioned missions load fine, because p.2 is false there.
But if I uncomment model_death on elemental, it still catches the error.

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
01.08.2022 19:59 stgatilov Note Added: 0015111
01.08.2022 20:19 stgatilov Note Edited: 0015111
01.08.2022 20:30 stgatilov Note Added: 0015112