0025689: IGESCAFControl_Writer crash in constructor.
authorakz <akz@opencascade.com>
Mon, 26 Jan 2015 16:12:41 +0000 (19:12 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 5 Feb 2015 11:45:46 +0000 (14:45 +0300)
Cause of bug is that the IGESData_BasicEditor is created before an initialization of IGESControl_Controller::Init(). IGESData_BasicEditor cannot find template "iges", so the model is still empty after creation.

1) Added a default constructor to the IGESData_BasicEditor. Can be initialized via Init() method.
2) Added some null checks in the places, where are provided access to the model (IGESData_BasicEditor's member).
3) Initialization of the IGESData_BasicEditor was placed after initialization if the IGESControl_Controller.

src/IGESControl/IGESControl_Writer.cxx
src/IGESData/IGESData_BasicEditor.cdl
src/IGESData/IGESData_BasicEditor.cxx

index 99ef6dd..dcaca3a 100644 (file)
 
 IGESControl_Writer::IGESControl_Writer ()
     :  theTP (new Transfer_FinderProcess(10000)) ,
 
 IGESControl_Writer::IGESControl_Writer ()
     :  theTP (new Transfer_FinderProcess(10000)) ,
-       thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
        thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
        thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
+  thedit.Init(IGESSelect_WorkLibrary::DefineProtocol());
   thedit.SetUnitName(Interface_Static::CVal ("write.iges.unit"));
   thedit.ApplyUnit(); 
   thecr = Interface_Static::IVal ("write.iges.brep.mode");
   thedit.SetUnitName(Interface_Static::CVal ("write.iges.unit"));
   thedit.ApplyUnit(); 
   thecr = Interface_Static::IVal ("write.iges.brep.mode");
@@ -62,11 +62,11 @@ IGESControl_Writer::IGESControl_Writer ()
 IGESControl_Writer::IGESControl_Writer
   (const Standard_CString unit, const Standard_Integer modecr)
     :  theTP (new Transfer_FinderProcess(10000)) ,
 IGESControl_Writer::IGESControl_Writer
   (const Standard_CString unit, const Standard_Integer modecr)
     :  theTP (new Transfer_FinderProcess(10000)) ,
-       thedit (IGESSelect_WorkLibrary::DefineProtocol()) ,
        thecr (modecr) , thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
        thecr (modecr) , thest (Standard_False)
 {
 //  faudrait aussi (?) prendre les parametres par defaut ... ?
   IGESControl_Controller::Init();
+  thedit.Init(IGESSelect_WorkLibrary::DefineProtocol());
   thedit.SetUnitName(unit);
   thedit.ApplyUnit();
   themod = thedit.Model();
   thedit.SetUnitName(unit);
   thedit.ApplyUnit();
   themod = thedit.Model();
index 1189621..014f8f6 100644 (file)
@@ -31,12 +31,21 @@ uses GeneralLib, SpecificLib,
 
 is
 
 
 is
 
+       Create returns BasicEditor;
+       ---Purpose : Creates an empty Basic Editor which should be initialized via Init() method.
+
     Create (protocol : Protocol from IGESData)  returns BasicEditor;
     ---Purpose : Creates a Basic Editor, with a new IGESModel, ready to run
 
     Create (model : IGESModel; protocol : Protocol from IGESData)
        returns BasicEditor;
     ---Purpose : Creates a Basic Editor for IGES Data, ready to run
     Create (protocol : Protocol from IGESData)  returns BasicEditor;
     ---Purpose : Creates a Basic Editor, with a new IGESModel, ready to run
 
     Create (model : IGESModel; protocol : Protocol from IGESData)
        returns BasicEditor;
     ---Purpose : Creates a Basic Editor for IGES Data, ready to run
+       
+       Init (me : in out; protocol : Protocol from IGESData);
+    ---Purpose : Initialize a Basic Editor, with a new IGESModel, ready to run
+
+    Init (me : in out; model : IGESModel; protocol : Protocol from IGESData);
+    ---Purpose : Initialize a Basic Editor for IGES Data, ready to run
 
     Model  (me) returns IGESModel;
     ---Purpose : Returns the designated model
 
     Model  (me) returns IGESModel;
     ---Purpose : Returns the designated model
index 0db32f3..cc86f54 100644 (file)
 #include <UnitsMethods.hxx>
 
 
 #include <UnitsMethods.hxx>
 
 
-IGESData_BasicEditor::IGESData_BasicEditor
+IGESData_BasicEditor::IGESData_BasicEditor(const Handle(IGESData_Protocol)&  protocol)
+{
+  Init(protocol);
+}
+
+IGESData_BasicEditor::IGESData_BasicEditor(const Handle(IGESData_IGESModel)& model,
+                                           const Handle(IGESData_Protocol)& protocol)
+{
+  Init(model, protocol);
+}
+
+IGESData_BasicEditor::IGESData_BasicEditor() {  }
 
 
-  (const Handle(IGESData_Protocol)&  protocol)
-  : theunit (Standard_False) , theproto (protocol) ,
-    themodel (GetCasted(IGESData_IGESModel,Interface_InterfaceModel::Template("iges"))) ,
-    theglib (protocol) , theslib (protocol)     {  }
+void IGESData_BasicEditor::Init (const Handle(IGESData_Protocol)& protocol)
+{
+  theunit = Standard_False;
+  theproto = protocol;
+  themodel = GetCasted(IGESData_IGESModel,Interface_InterfaceModel::Template("iges"));
+  theglib = protocol;
+  theslib = protocol;
+}
 
 
-    IGESData_BasicEditor::IGESData_BasicEditor
-  (const Handle(IGESData_IGESModel)& model,
-   const Handle(IGESData_Protocol)&  protocol)
-  : theunit (Standard_False) , theproto (protocol) , themodel (model) ,
-    theglib (protocol) , theslib (protocol)    {  }
+void IGESData_BasicEditor::Init (const Handle(IGESData_IGESModel)& model, const Handle(IGESData_Protocol)& protocol)
+{
+  theunit = Standard_False;
+  theproto = protocol;
+  themodel = model;
+  theglib = protocol;
+  theslib = protocol;
+}
 
     Handle(IGESData_IGESModel)  IGESData_BasicEditor::Model () const
       {  return themodel;  }
 
     Handle(IGESData_IGESModel)  IGESData_BasicEditor::Model () const
       {  return themodel;  }
@@ -56,6 +74,7 @@ IGESData_BasicEditor::IGESData_BasicEditor
     Standard_Boolean IGESData_BasicEditor::SetUnitFlag
   (const Standard_Integer flag)
 {
     Standard_Boolean IGESData_BasicEditor::SetUnitFlag
   (const Standard_Integer flag)
 {
+  if (themodel.IsNull()) return Standard_False;
   if (flag < 1 || flag > 11) return Standard_False;
   IGESData_GlobalSection GS = themodel->GlobalSection();
   Handle(TCollection_HAsciiString) name = GS.UnitName();
   if (flag < 1 || flag > 11) return Standard_False;
   IGESData_GlobalSection GS = themodel->GlobalSection();
   Handle(TCollection_HAsciiString) name = GS.UnitName();
@@ -95,6 +114,7 @@ IGESData_BasicEditor::IGESData_BasicEditor
 //=======================================================================
 Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
 {
 //=======================================================================
 Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
 {
+  if (themodel.IsNull()) return Standard_False;
   Standard_Integer flag = IGESData_BasicEditor::UnitNameFlag (name);
   IGESData_GlobalSection GS = themodel->GlobalSection();
   if (GS.UnitFlag() == 3) {
   Standard_Integer flag = IGESData_BasicEditor::UnitNameFlag (name);
   IGESData_GlobalSection GS = themodel->GlobalSection();
   if (GS.UnitFlag() == 3) {
@@ -110,6 +130,7 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
 
     void  IGESData_BasicEditor::ApplyUnit (const Standard_Boolean enforce)
 {
 
     void  IGESData_BasicEditor::ApplyUnit (const Standard_Boolean enforce)
 {
+  if (themodel.IsNull()) return;
   if (!enforce && !theunit) return;
   IGESData_GlobalSection GS = themodel->GlobalSection();
   Standard_Real unit = GS.UnitValue();
   if (!enforce && !theunit) return;
   IGESData_GlobalSection GS = themodel->GlobalSection();
   Standard_Real unit = GS.UnitValue();
@@ -128,6 +149,7 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
 
     void  IGESData_BasicEditor::ComputeStatus ()
 {
 
     void  IGESData_BasicEditor::ComputeStatus ()
 {
+  if (themodel.IsNull()) return;
   Standard_Integer nb = themodel->NbEntities();
   if (nb == 0) return;
   TColStd_Array1OfInteger subs (0,nb); subs.Init(0); // gere Subordinate Status
   Standard_Integer nb = themodel->NbEntities();
   if (nb == 0) return;
   TColStd_Array1OfInteger subs (0,nb); subs.Init(0); // gere Subordinate Status
@@ -216,6 +238,7 @@ Standard_Boolean IGESData_BasicEditor::SetUnitName (const Standard_CString name)
     Standard_Boolean  IGESData_BasicEditor::AutoCorrect
   (const Handle(IGESData_IGESEntity)& ent)
 {
     Standard_Boolean  IGESData_BasicEditor::AutoCorrect
   (const Handle(IGESData_IGESEntity)& ent)
 {
+  if (themodel.IsNull()) return Standard_False;
   Handle(IGESData_IGESEntity) bof, subent;
   Handle(IGESData_LineFontEntity) linefont;
   Handle(IGESData_LevelListEntity) levelist;
   Handle(IGESData_IGESEntity) bof, subent;
   Handle(IGESData_LineFontEntity) linefont;
   Handle(IGESData_LevelListEntity) levelist;