Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

Problem with FSD_File

Problem with FSD_File
Patrik Müller 2004/08/02 12:39
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 2004/08/04 12:28
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<char,std::char_traits<char>,std::allocator<char> >::`scalar deleting destructor'(unsigned int 1) + 34 bytes
std::basic_filebuf<char,std::char_traits<char> >::~basic_filebuf<char,std::char_traits<char> >() line 78 + 31 bytes
std::basic_fstream<char,std::char_traits<char> >::~basic_fstream<char,std::char_traits<char> >() line 357 + 66 bytes
std::basic_fstream<char,std::char_traits<char> >::`vbase destructor'() + 18 bytes
FSD_File::~FSD_File() line 232 + 18 bytes


Greets,

Patrik
PG 2007/03/16 08:25
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 Müller 2007/03/17 19:04
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 2009/01/30 13:35
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 <FSD_File.hxx>


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 2009/01/30 14:41
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.
Nair Sharjith 2009/02/03 04:43
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 2009/02/03 09:30
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
Nair Sharjith 2009/02/03 15:28
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 2009/02/03 15:47
Well, don't know then. In my case the problem was mixing different runtime versions / configurations...
holinz 2013/05/06 09:59
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
 
 
Latest news
  • OCCT Applications
  • Open CASCADE Technology 6.8.0 is available for download!
  • New features to enhance the development process

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map