Crash when using ClearSelected

I am a newbie for opencascade. Firstly, I selected a shape from list control using SetSelected and it works. Then I select no item. It crashed in void AIS_LocalContext::UnhilightPicked (const Standard_Boolean theToUpdateViewer) function when calling ClearSelected().

The follow is the source.

void CObjListWnd::OnNMClickObjList(NMHDR * pNMHDR, LRESULT * pResult)

{

LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);

int nItem = pNMItemActivate->iItem;  // Get selected item index

CHSW_OCCDoc* pDoc = static_cast<CHSW_OCCDoc*>(((CHSW_OCCApp*)AfxGetApp())->GetActiveDoc());

Handle(AIS_InteractiveContext) anAIScontext = pDoc->GetAISContext();



if (nItem == -1)   // Selected no item

{

anAIScontext->ClearSelected();  // Clear selection

return;

}



Handle(AIS_Shape) ais = new AIS_Shape(GetSelectShape(nItem)); //Get the shape from selected index

anAIScontext->SetSelected(ais);   // Set selection

*pResult = 0;

}

Is there a bug or I use it incorrectly?

Byron Xiong's picture

It won't crash if I add CloseAllContexts before SetSelected. But the color of the shape won't be cleared. For example, a yellow line will turn to red if I select it, but it won't restore to yellow after I clearing selection.

Kirill Gavrilov's picture

I cannot comment if it is a bug or not, but this functionality has been deprecated and will be removed in next versions anyway - better porting application to not use Local Context.