From 3ceab7ef3f80a5bd129e6bdbf1e478de3c05744f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 26 Aug 2009 13:16:40 +0000 Subject: [PATCH] Fixed problem with the AddPathCommand. When ownership of the added paths is not transfered to the commmand, it needs to add references. If not more of such problems are lurking, it could already fix ticket #4104. Note that you can build Icon-O-Matic with referencable tracing turned on (generic/support/ Referenceable.cpp). The backtrace in #4104 would specifically hint at a problem with assigning paths to shape and then unassigning them. Assigning them didn't add the references that unassigning the paths removed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32707 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../shape/commands/AddPathsCommand.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/apps/icon-o-matic/shape/commands/AddPathsCommand.cpp b/src/apps/icon-o-matic/shape/commands/AddPathsCommand.cpp index c633ef3c9b..95d78c49a1 100644 --- a/src/apps/icon-o-matic/shape/commands/AddPathsCommand.cpp +++ b/src/apps/icon-o-matic/shape/commands/AddPathsCommand.cpp @@ -35,14 +35,24 @@ AddPathsCommand::AddPathsCommand(PathContainer* container, return; memcpy(fPaths, paths, sizeof(VectorPath*) * fCount); + + if (!fOwnsPaths) { + // Add references to paths + for (int32 i = 0; i < fCount; i++) { + if (fPaths[i] != NULL) + fPaths[i]->Acquire(); + } + } } // destructor AddPathsCommand::~AddPathsCommand() { - if (fOwnsPaths && !fPathsAdded && fPaths) { - for (int32 i = 0; i < fCount; i++) - fPaths[i]->Release(); + if (!fPathsAdded && fPaths) { + for (int32 i = 0; i < fCount; i++) { + if (fPaths[i] != NULL) + fPaths[i]->Release(); + } } delete[] fPaths; } @@ -58,23 +68,18 @@ AddPathsCommand::InitCheck() status_t AddPathsCommand::Perform() { - status_t ret = B_OK; - // add paths to container - int32 index = fIndex; for (int32 i = 0; i < fCount; i++) { - if (fPaths[i] && !fContainer->AddPath(fPaths[i], index)) { - ret = B_ERROR; + if (fPaths[i] && !fContainer->AddPath(fPaths[i], fIndex + i)) { // roll back for (int32 j = i - 1; j >= 0; j--) fContainer->RemovePath(fPaths[j]); - break; + return B_ERROR; } - index++; } fPathsAdded = true; - return ret; + return B_OK; } // Undo