For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Problem with FSD_File

Anonymous's picture
Forums: 

Hi all,

I use the following code for writing files:

IFSelect_ReturnStatus result = IFSelect_RetFail;
if (!theViewer.IsNull())
{
if (!theViewer->GetRoot().IsNull())
{
Handle_Im_Scene myRoot = theViewer->GetRoot();
Standard_Integer nbEntries = myRoot->NbChildren();

FSD_File f;

Handle(ShapeSchema) s = new ShapeSchema;

Handle(Storage_Data) d = new Storage_Data;

d->ClearErrorStatus();

d->SetApplicationName (TCollection_ExtendedString("Imhotep"));
d->SetApplicationVersion(m_PluginInfo.m_PluginVersion);
d->SetDataType(TCollection_ExtendedString("Shapes"));
d->AddToUserInfo(m_PluginInfo.m_PluginName);
d->AddToComments(TCollection_ExtendedString("application is based on OpenCasCade 5.2"));

// Open the archive, Write mode
Storage_Error err = f.Open(FileName, Storage_VSWrite);

if ( err == Storage_VSOk )
{
PTColStd_TransientPersistentMap aMap;

Im_EntityListTraverser actIt(myRoot->GetChildren()->GetEntries());
for (actIt.InitEntries(); actIt.MoreEntries(); actIt.NextEntry())
{
Handle_Im_Entity3D tmp3D = Handle_Im_Entity3D::DownCast(actIt.Value());
if (!tmp3D.IsNull())
{
TopoDS_Shape aTShape= m_EntityUtil.Shape(tmp3D);
if (!aTShape.IsNull())
{
TCollection_AsciiString anObjectName(Im_IOHelpers::FixMatName(tmp3D->GetName()));
Handle(PTopoDS_HShape) aPShape = MgtBRep::Translate(aTShape, aMap, MgtBRepAbs_WithTriangle);
d->AddRoot(anObjectName, aPShape);
}
}
}
s->Write( f, d);

err = f.Close();
if ( d->ErrorStatus() == Storage_VSOk )
result = IFSelect_RetDone;
}
}
}
return result;

But now with OCC 5.2 I always get a crash when leaving the method. After some investigations it crashes in the FSD_File desctructor after "Destroy()".
I'm using VC6 SP6.

Anyone has a hint??

Best regards,

Patrik

Patrik Müller's picture

Hi,

perhaps this can give someone more infos about my problem:

NTDLL! 77f65a58()
NTDLL! 77f7c366()
KERNEL32! 77e4c75a()
_CrtIsValidHeapPointer(const void * 0x0eedad38) line 1697
_free_dbg_lk(void * 0x0eedad38, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x0eedad38, int 1) line 1001 + 13 bytes
free(void * 0x0eedad38) line 956 + 11 bytes
operator delete(void * 0x0eedad38) line 7 + 10 bytes
std::basic_string,std::allocator >::`scalar deleting destructor'(unsigned int 1) + 34 bytes
std::basic_filebuf >::~basic_filebuf >() line 78 + 31 bytes
std::basic_fstream >::~basic_fstream >() line 357 + 66 bytes
std::basic_fstream >::`vbase destructor'() + 18 bytes
FSD_File::~FSD_File() line 232 + 18 bytes

Greets,

Patrik

PG's picture

Hello Patrick,

Has this problem solved at ur end.
I am facing similar problem's with OCC 6.1.0.
I am also using this API but it crashes in Windows.
regards
PG

Patrik Mueller's picture

Hi,

hmm - haven't used FSD_File for some time. If I remember correctly the problem was mixing a debug version of my code with a release version of OCC. Have you tried your application in release mode??

Regards,

Patrik

Pawel's picture

Hi,

has anyone found the solution already? Up to OCC6.2 compiling in release mode did solve (or actually mask) the problem. Under OCC6.3 destructing the FSD_File causes crashes even in the release mode.

A small code sample to demonstrate the problem:

#include "tchar.h"
#include

int _tmain(int argc, _TCHAR* argv[])
{
FSD_File f;
printf("An exception is generated by dbgheap.c::_CrtIsValidHeapPointer before this command is reached.\n");
return 0;
}

Any comments?
Pawel

Pawel's picture

Apparently, mixing different compilation modes (debug/release) is not the only thing one should avoid. Using different compilers (or compiler versions) for OCC and the application should also avoided.

Compiling OCC and the app with one compiler seems to solve the problem.

By the way, I had similar symptoms trying to export VRML2.0 files.

Sharjith Naramparambath's picture

Hi All,

I have solved this problem by making FSD_File a pointer member variable of the class Translate and creating on the heap in the constructor and deleting in the destructor of class Translate as compared to what it is (static variable) in the sample. The crash has disappeared.

Pawel's picture

Hi Nair,

I just made a small modification of the code snippet:

int _tmain(int argc, _TCHAR* argv[])
{
FSD_File *f = new FSD_File();
delete f;
printf("An exception is generated by dbgheap.c::_CrtIsValidHeapPointer before this command is reached.\n");
return 0;
}

and I have to say the problem does exist. Are you sure you're calling the destructor.

I guess your solution might just mask the problem.

Pawel

Sharjith Naramparambath's picture

The destructor is being called 100%. I am using gtk and hence I ported the entire Qt code as it is with a GtkWidget* as the member variable for dialog in the class Translate. I have put the FSD_File* fileDriver as the member variable and initialized it with fileDriver = new FSD_File(); in the coinstructor and then using it to open file wherever the import/export code is, with the following lines...

if ( fileDriver->Open( aName, Storage_VSRead ) != Storage_VSOk )
return aSequence;

etc... and then in the destructor I am calling the line

if(fileDriver != NULL)
{
fileDriver->Close(); // can close here since one instance called for one import/export
delete fileDriver;
}

I have run debug several times with all import/export formats to ensure the functioning.

Any doubts??

Pawel's picture

Well, don't know then. In my case the problem was mixing different runtime versions / configurations...

holinz's picture

It works!By making FSD_File a pointer member variable of the class Translate and creating on the heap in the constructor and deleting in the destructor of class Translate as compared to what it is (static variable) in the sample. The crash has disappeared.
note: win7 64bit 6.53