View Issue Details

IDProjectCategoryView StatusLast Update
0004199The Dark ModAnimationpublic13.08.2015 18:48
ReporterNagaHuntress Assigned ToSteveL  
PrioritynormalSeveritynormalReproducibilityalways
Status resolvedResolutionfixed 
Product VersionTDM 2.03 
Target VersionTDM 2.04Fixed in VersionTDM 2.04 
Summary0004199: Melee weapon attacks and parries don't work under certain compilers.
DescriptionIn function idAnim::CallFrameCommands() case FC_MELEE_ATTACK_START and FC_MELEE_PARRY_START have the following code for extracting weapon names and attack/parry names:

const char *WeapName, *ParName;
int spcind = command.string->Find(" ");
WeapName = command.string->Left( spcind ).c_str();
ParName = command.string->Mid( spcind+1, command.string->Length() );

What happens is that Left() creates a temporary idStr, and WeapName stores a pointer to its C string. Because this string is short, it will use idStr's internal base buffer and not allocate anything from the heap. Then once line has finished excuting it deletes the temporary idStr, leaving WeapName with a stale pointer.


On the next line Mid() then creates a new temporary idStr and AttName/ParName stores a pointer to its C string of that. This new temporary idStr reuses the storage for the previous temporary idStr. Because the storage is recycled, the two strings pointers (WeapName and AttName/ParName) point to the same string, which is what's meant to be in AttName/ParName.

The end result is that WeapName doesn't name a weapon name, so the weapon look up fails and it can't do the actual weapon attack/parry, however, it still plays the animation.

Whether or not this bug manifest depends upon when it deletes the temporary idStr for WeapName. If immediately it will bug with melee weapons having no effect, or if its deleted when the scope ends the bug won't happen. So ultimately its dependant on the compiler, and possibly it's optimisation options.
Steps To ReproduceCompile with GCC 4.8.4 on Linux Mint 17.2 (other versions, compilers and OSes/distros are probably affected)
TagsNo tags attached.

Activities

NagaHuntress

NagaHuntress

12.08.2015 01:52

reporter  

tdm--melee-weapon-attack-parry-fix.diff (1,777 bytes)   
Index: game/anim/Anim_Blend.cpp
===================================================================
--- game/anim/Anim_Blend.cpp	(revision 6527)
+++ game/anim/Anim_Blend.cpp	(working copy)
@@ -26,7 +26,13 @@
 #include "../DarkModGlobals.h"
 #include "../MeleeWeapon.h"
 #include "../ai/Tasks/SingleBarkTask.h"
+#include "anim/Anim.h"
+#include "ai/AI.h"
+#include "Player.h"
+#include "FX.h"
+#include "Weapon.h"
 
+
 static const char *channelNames[ ANIM_NumAnimChannels ] = {
 	"all", "torso", "legs", "head", "eyelids"
 };
@@ -1617,12 +1623,11 @@
 				}
 				case FC_MELEE_ATTACK_START:
 				{
-					const char *WeapName, *AttName;
 					int spcind = command.string->Find(" ");
-					WeapName = command.string->Left( spcind ).c_str();
-					AttName = command.string->Mid( spcind+1, command.string->Length() );
+					idStr WeapName = command.string->Left( spcind );
+					const char *AttName = command.string->c_str() + spcind+1;
 					
-					idEntity *AttEnt = ent->GetAttachment( WeapName );
+					idEntity *AttEnt = ent->GetAttachment( WeapName.c_str() );
 					if( AttEnt && AttEnt->IsType(CMeleeWeapon::Type) )
 					{
 						idActor *ActOwner;
@@ -1662,12 +1667,11 @@
 				}
 				case FC_MELEE_PARRY_START:
 				{
-					const char *WeapName, *ParName;
 					int spcind = command.string->Find(" ");
-					WeapName = command.string->Left( spcind ).c_str();
-					ParName = command.string->Mid( spcind+1, command.string->Length() );
+					idStr WeapName = command.string->Left( spcind );
+					const char *ParName = command.string->c_str() + spcind+1;
 					
-					idEntity *AttEnt = ent->GetAttachment( WeapName );
+					idEntity *AttEnt = ent->GetAttachment( WeapName.c_str() );
 					if( AttEnt && AttEnt->IsType(CMeleeWeapon::Type) )
 					{
 						idActor *ActOwner;
SteveL

SteveL

13.08.2015 18:48

reporter   ~0007713

Patch committed at rev 6528

game/anim/Anim_Blend.cpp

Issue History

Date Modified Username Field Change
12.08.2015 01:52 NagaHuntress New Issue
12.08.2015 01:52 NagaHuntress File Added: tdm--melee-weapon-attack-parry-fix.diff
13.08.2015 18:22 SteveL Assigned To => SteveL
13.08.2015 18:22 SteveL Status new => assigned
13.08.2015 18:22 SteveL Product Version => TDM 2.03
13.08.2015 18:22 SteveL Target Version => TDM 2.04
13.08.2015 18:48 SteveL Note Added: 0007713
13.08.2015 18:48 SteveL Status assigned => resolved
13.08.2015 18:48 SteveL Fixed in Version => TDM 2.04
13.08.2015 18:48 SteveL Resolution open => fixed