The usage of AIS_ColoredShape::SetCustomColor

I want to change the color of the face which is selected, the face belongs to a object in the context . And I think the function "AIS_ColoredShape::SetCustomColor" can solve this problem.However , When I use it in my Qt project ,it crashed . Here is my poor C++ code .I will appreciate if any help.

    Handle(AIS_InteractiveObject) Current = theContext->SelectedInteractive() ;

    TopoDS_Shape targetShape = theContext->SelectedShape();

    Handle(AIS_ColoredShape) sourceColorShape = Handle(AIS_ColoredShape)::DownCast(Current);

    sourceColorShape->SetCustomColor(targetShape ,color);//color was specified before



Kirill Gavrilov's picture

Build Debug builds of OCCT libraries and your application, so that debugger will help to see why code crashes.