User forums > Using Code::Blocks

Delete an active target

<< < (2/3) > >>

BlueHazzard:
The problem is, that the member variable "m_LastTarget" of MacrosManager points to an invalid target after the target is deleted.

The question is how to solve this issue?
1) Reset the MacrosManager if a target is deleted?
2) Only if the "current target == m_LastTarget"?
3) Reset only "m_LastTarget" if the target is deleted?

2) should probably be the solution to go..

oBFusCATed:
What do you mean by 2? I don't understand.

BlueHazzard:

--- Quote from: oBFusCATed on January 07, 2019, 07:31:40 pm ---What do you mean by 2? I don't understand.

--- End quote ---

--- Code: ---if(&deleteTarget==&m_LastTarget)
{
MacrosManager::Reset();
}
--- End code ---
This would be a quick fix.

A proper fix would be to use shared_ptr<> and weak_ptr<> on every place a target pointer is used...

oBFusCATed:

--- Quote from: BlueHazzard on January 07, 2019, 10:07:44 pm ---A proper fix would be to use shared_ptr<> and weak_ptr<> on every place a target pointer is used...

--- End quote ---
I'm not really sure this would be a good idea. For sure it would be quite hard to implement, because you'll probably have to change every file in the repo.

BlueHazzard:

--- Code: ---@@ -1310,10 +1310,11 @@ bool cbProject::RemoveBuildTarget(int index)
         // finally remove the target
         delete target;
         m_Targets.RemoveAt(index);
         SetModified(true);
         NotifyPlugins(cbEVT_PROJECT_TARGETS_MODIFIED);
+        Manager::Get()->GetMacrosManager()->Reset();
         return true;
     }
     return false;
 }
 

--- End code ---

This fixes this bug...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version