How to correctly delete new workspace in c++

How to correctly delete new workspace in c++

lsRDZZQ
Participant Participant
1,089 Views
2 Replies
Message 1 of 3

How to correctly delete new workspace in c++

lsRDZZQ
Participant
Participant

Hello,

 

How to correctly delete the new created workspace object in c++? 

If I'm in the new created workspace, then the following code crashes fusion 360. If i go to solid workspace and stop the addin, everything works well. so how to avoid this kind of problems. thanks

 

 

extern "C" XI_EXPORT bool stop(const char* context)
{
	if (!ui)
		return false;

	/**
    * Get global objs
    */
	Ptr<Toolbars> toolbars = ui->toolbars();
	if (!toolbars)
		return false;
	Ptr<CommandDefinitions> cmdDefs = ui->commandDefinitions();
	if (!cmdDefs)
		return false;
	Ptr<Workspaces> workspaces = ui->workspaces();
	if (!workspaces)
		return false;
    
    /*
    * Get and release user def objs
    */
	//Ptr<Workspace> simericsWorkspace = workspaces->itemById(simericsExistWorkspaceId);
    Ptr<Workspace> simericsWorkspace = workspaces->itemById(simericsWorkspaceId);
	if (!simericsWorkspace)
		return false;
	Ptr<ToolbarPanels> tbPanels = simericsWorkspace->toolbarPanels();
	if (!tbPanels)
		return false;
	Ptr<ToolbarPanel> tbPanel = tbPanels->itemById(simericsPanelId);
	if (!tbPanel)
		return false;
	Ptr<ToolbarControls> tbPanelCtrls = tbPanel->controls();
	if (!tbPanelCtrls)
		return false;
	Ptr<ToolbarControl> tbComCtrl = tbPanelCtrls->itemById(simericsComId);
	Ptr<CommandDefinition> cmdDef = cmdDefs->itemById(simericsComId);

    if (tbPanel)
        tbPanel->deleteMe();
    if (simericsWorkspace)
        simericsWorkspace->deleteMe();
	if (tbComCtrl)
		tbComCtrl->deleteMe();
	if (cmdDef)
		cmdDef->deleteMe();

	return true;
}

 

0 Likes
Accepted solutions (1)
1,090 Views
2 Replies
Replies (2)
Message 2 of 3

liujac
Alumni
Alumni
Accepted solution

Hi,

 

Thanks for reporting this issue. I logged a defect (UP-29294) in our internal system. We will fix it.

 

For now, the workaround is to check if the workspace to be deleted is active, activate another workspace (Workspace.activate()) if the workspace to be deleted is active, and then delete your workspace.

 

Thanks,

Jack

0 Likes
Message 3 of 3

lsRDZZQ
Participant
Participant

Hi liujac,

 

The solution you provided works well. thanks!

 

0 Likes