Various fixed

* Fixed potential invalid pointer dereferencing, fixes #1117
* Fixed ender pearls not being loaded properly
This commit is contained in:
Tiger Wang
2014-07-04 16:49:24 +01:00
parent f635066241
commit f4e3c01a71
4 changed files with 111 additions and 17 deletions
+30 -4
View File
@@ -66,8 +66,15 @@ public:
/// Returns the kind of the projectile (fast class identification)
eKind GetProjectileKind(void) const { return m_ProjectileKind; }
/// Returns the entity who created this projectile; may be NULL
cEntity * GetCreator(void) { return m_Creator; }
/** Returns the entity who created this projectile through running its Unique ID through cWorld::DoWithEntityByID()
May return NULL; do not store the returned pointer outside the scope of the tick thread!
*/
cEntity * GetCreator(void);
/** Returns the name of the player that created the projectile
Will be empty for non-player creators
*/
AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
/// Returns the string that is used as the entity type (class name) in MCA files
AString GetMCAClassName(void) const;
@@ -81,10 +88,29 @@ public:
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
protected:
/** A structure that stores the Entity ID and Playername of the projectile's creator
Used to migitate invalid pointers caused by the creator being destroyed
*/
struct CreatorData
{
CreatorData(int a_UniqueID, AString & a_Name) :
m_UniqueID(a_UniqueID),
m_Name(a_Name)
{
}
const int m_UniqueID;
AString m_Name;
};
/** The type of projectile I am */
eKind m_ProjectileKind;
/// The entity who has created this projectile; may be NULL (e. g. for dispensers)
cEntity * m_Creator;
/** The structure for containing the entity ID and name who has created this projectile
The ID and/or name may be NULL (e.g. for dispensers/mobs)
*/
CreatorData m_CreatorData;
/// True if the projectile has hit the ground and is stuck there
bool m_IsInGround;