From e0d028bed2682ea3a1ecf379cf285ed2758ae719 Mon Sep 17 00:00:00 2001 From: Wanne Date: Thu, 22 Nov 2012 23:16:03 +0000 Subject: [PATCH] - Fixed CTD that could happen when removing attachments (by Realist) o The CTD always happened in Old Attachment System (OAS) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5697 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index b84130db..e5d71588 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -7981,7 +7981,7 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE* pAttachment, OBJECTTYPE * pNew { removedAttachment = *pAttachment; iter = (*this)[subObject]->RemoveAttachmentAtIter(iter); - + pAttachment = NULL; objDeleted = TRUE; break; } @@ -7995,7 +7995,7 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE* pAttachment, OBJECTTYPE * pNew { removedAttachment = *pAttachment; iter = (*this)[subObject]->RemoveAttachmentAtIter(iter); - + pAttachment = NULL; objDeleted = TRUE; break; } @@ -8097,8 +8097,11 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE* pAttachment, OBJECTTYPE * pNew if(pNewObj != NULL) *pNewObj = removedAttachment; - if(pAttachment->exists() && (pAttachment->usItem == 0 || pAttachment->usItem == removedAttachment.usItem )) - *pAttachment = removedAttachment; + + // Why is this here? By now, the object, pAttachment had been pointing to, has already been deconstructed via RemoveAttachmentAtIter. + // (Commenting out the following two lines) + //if(pAttachment->exists() && (pAttachment->usItem == 0 || pAttachment->usItem == removedAttachment.usItem )) + // *pAttachment = removedAttachment; if (pNewObj->exists() && Item[pNewObj->usItem].grenadelauncher )//UNDER_GLAUNCHER) {