Error with a .stp model during transfer from STEPCAFControl_Reader to document

Hi all,

I'm having a crash problem in STEPCAFControl_Reader::Transfer(Handle &doc) with a set of .stp models. The models that give me problems are exported with SolidWorks 2011 as AP_214 (in order to support colours). If I export them as AP_203 the same code works correctly (without colours).

I have this error only with OpenCascade 6.5.2 while with OpenCascade 6.5.1 operation works well.

Among attachments a simple model that give me the problem.

At the end of this post a simple code to test the error.

Thanks in advance,
Francesco Argese

// C++ standard headers
#include

// OpenCascade headers
#include

// Project headers
#include "MyOcafApplication.h"

int main(int argc, char **argv)
{
std::string fileName="C:/Sviluppo/SolidWorks_test/Parte2.STEP";

// Create an OpenCascade Application
MyOcafApplication *mCasApp = new MyOcafApplication();
Handle(TDocStd_Document) doc;
mCasApp->NewDocument("MDTV-XCAF", doc);

// Reader for .stp cad model to load into a document
STEPCAFControl_Reader stepReader;

// Read file
IFSelect_ReturnStatus status = stepReader.ReadFile(fileName.c_str());
if ( status != IFSelect_RetDone )
return false;

// Set modes
stepReader.SetColorMode(Standard_True);
stepReader.SetLayerMode(Standard_True);
stepReader.SetNameMode(Standard_True);

// Transfer to doc passed as argument
Standard_Boolean ok = stepReader.Transfer(doc); // ERROR HERE!!!

delete mCasApp;

return 0;
}

where OCAFApplication.h is the following:

#ifndef __TDOC_STD_APPLICATION__
#define __TDOC_STD_APPLICATION__

// OpenCascade headers
#include
#include

/*!
* \class MyOcafApplication
* \inherit TDocStd_Application
* \brief Class inherited from OpenCascade's TDocStd_Application. It is needed to use a TDocStd_Application that is an abstract class!
*/
class MyOcafApplication : public TDocStd_Application
{
/*!
* \fn void Formats(TDolStd_SequenceOfExtendedString& Formats)
* \brief Method to add the format of the documents to be read by the application
* \param Formats
*/
void Formats(TColStd_SequenceOfExtendedString& Formats)
{
Formats.Append(TCollection_ExtendedString("MyOcafApplication"));
}

/*!
* \fn Standard_CString ResourcesName()
* \brief method to define the name of the resource file
*/
Standard_CString ResourcesName()
{
return Standard_CString("Resources");
}

};

#endif // __TDOC_STD_APPLICATION__

Attachments: 
Forum supervisor's picture

Dear Francesco,
I would like to inform you that the posted problem has been checked and reproduced.
I suggest you to register the issue in Mantis Bugtracker which is available now via the Collaborative portal - http://dev.opencascade.org/index.php?q=home/get_involved.

At the same time I would like to note that in spite of the exception the document is created.
So,
1)temporary you may try to catch the exception and use the Document in usual mode.
I extracted the shape located at the label 0:1:1:1 for your information (see the attached picture).
The shape is valid and cas the next sub-shapes:
Number of shapes in S
VERTEX : 16
EDGE : 24
WIRE : 16
FACE : 12
SHELL : 1
SOLID : 1
COMPSOLID : 0
COMPOUND : 0
SHAPE : 70

2) If you need only shape you may use directly step reader (without document creation).
It perfectly reads the specified step file (the STEPControl_Reader is used).
Draw reproducer:
pload ALL
stepread Parte2.STEP s *
Below I put the command output:
... Step File Reading : Parte2.STEP
... STEP File Read ...
Elapsed time: 0 Hours 0 Minutes 0.00627949787304 Seconds
CPU user time: 0 seconds
CPU system time: 0 seconds
... Step File loaded ...
Elapsed time: 0 Hours 0 Minutes 0.00953773991205 Seconds
CPU user time: 0 seconds
CPU system time: 0 seconds
580 records (entities,sub-lists,scopes), 1623 parameters

... Parameters prepared ... Elapsed time: 0 Hours 0 Minutes 0.01553024241 Seconds
CPU user time: 0 seconds
CPU system time: 0.0156001 seconds
Report : 1 unknown entities.
... Objets analysed ...
Elapsed time: 0 Hours 0 Minutes 0.0201196207781 Seconds
CPU user time: 0 seconds
CPU system time: 0.0156001 seconds
STEP Loading done : 374 Entities
Preprocessor version detected: SwSTEP 2.0
//What is?// NB COMPOUNDS: 1
//What is?// NB SOLIDS: 1
//What is?// NB SHELLS: 1
//What is?// OPEN SHELLS: 0
//What is?// CLOSED SHELLS: 1
//What is?// NB FACES: 12
//What is?// NB WIRES: 16
//What is?// NB EDGES: 24
//What is?// NB VERTEXES: 16
File STEP to read : Parte2.STEP
-- Names of variables BREP-DRAW prefixed by : s
Transferrable Roots : Nb entities selected : 1
Transfer entity n0 162 OK -> DRAW Shape: s_1
Now, 1 Shapes produced
So, the resulting shape 's_1' seems the same as the previous shape 'S'
Number of shapes in s_1
VERTEX : 16
EDGE : 24
WIRE : 16
FACE : 12
SHELL : 1
SOLID : 1
COMPSOLID : 0
COMPOUND : 0
SHAPE : 70
You may use it.

Regards

Attachments: 
Francesco Argese's picture

I have tried to catch the exception with:

try
{
Standard_Boolean ok = stepReader.Transfer(doc);
}
catch(std::exception exp)
{
std::cout << "Exception caught: " << exp.what() << std::endl;
}

In debugging mode I obtain the same error. From the message it seems that the heap could be corrupted.

I have registered an issue with id 0023010 in Mantis BugTracker [1].

Thank you very much,
Francesco Argese

[1] http://tracker.dev.opencascade.org/view.php?id=23010