
Tue, 01/29/2008 - 16:36
Hi,
I'm trying to save an OCAF document I have generated. Here an memory access exception raises.
The OCAF doc is OK - I've printed it out directly before saving it.
The save-command looks like this:
storeStatus = application->SaveAs(document, "C:/testfile.geometry");
Now the following functions are called directly before the error raises:
TDocStd_Application::SaveAs()
CDF_Store::CDF_Store()
CDF_Store::Init()
CDF_Store::FindDefault()
CDF_Application::DefaultFolder()
TCollection_ExtendedString::Copy()
Standard::Reallocate()
Standard_MMgrOpt::Reallocate()
Standard_MMgrOpt::Free()
In Free() there is a line
*(Standard_Address*)aStorage = myFreeList[Index];
where the application crashes as myFreeList is NULL.
Has anyone any suggestion how to solve this problem?
Thanks a lot in advance !
Tue, 01/29/2008 - 16:55
Do you use OCC in one thread only? If no then try using reentrant mode of memory manager (MMGT_REENTRANT).
Tue, 01/29/2008 - 18:23
I've tried to change the environment variable MMGT_REENTRANT. But no matter if I set it to 0 or 1, the behaviour is exactly the same.
When setting
MMGT_OPT=0
the exception rises here in the entity->Delete() function:
void EndScope()
{
if (entity != UndefinedHandleAddress)
{
entity->count--;
if (entity->count == 0) {
entity->Delete();
entity = UndefinedHandleAddress ;
}
}
Tue, 01/29/2008 - 18:33
Sorry, I didn't response to your question itself: There is one thread only.
Tue, 01/29/2008 - 18:50
Hello !
I have rarely seen an unallocated smart pointer (entity) having an address with a small +offset from the "UndefinedHandleAddress",so the library thinks it is allocated and tries to delete it (cannot say why this happens...).If the functions called is a stack dump then it seems it tries to reallocate the CDF_Application::DefaultFolder().One problem might be that you did not put a double "\\" for the disk access but a "/".Maybe occ is aware of that but i am not sure.Worth to give it a try.Another idea is try to set the DefaultFolder by calling SetDefaultFolder from your application class.
Sioutis Fotis
Wed, 01/30/2008 - 10:46
I've tried both, the "\\" and setting the default folder.
Using "\\" does not change anything. Setting the default folder leads to a different behaviour:
When calling the saveAs method, the path of functions is the same till MMgrOpt::Reallocate(). Here it goes on with the line
memset((Standard_Address)((long)newStorage+newSize), 0, oldSize-newSize);
This calls
TKernel # Standard::Free()
and crashes with
msvcr80d.dll # _VEC_memzero()
Wed, 01/30/2008 - 11:22
I did a test case in my OCAF application, and i could not see any problem, even with your first case.My environment variables concerning the memory manager are:
MMGT_OPT=1 //use the optimised memory manager
MMGT_CLEAR=1 //this is important , at least in my case.Many problems could rise if i did not set this variable.Sets all bits of new allocated memory to NULL.
MMGT_REENTRANT=0 //My application is not multi threaded , so i do not need this.
If you have not set the MMGT_CLEAR then give it a try.
Greetings
Sioutis Fotis
Wed, 01/30/2008 - 11:39
Thanks, Sioutis,
but setting MMGT_CLEAR to 1 has no effect.
Do you have any other suggestion how to find the cause of the error?
Wed, 01/30/2008 - 11:50
Try using some memory checking tool, like Purify. The problem may be somewhere in your code due to incorrect working with memory, or using uninitialized variables, a memory checker will help you.
Fri, 02/01/2008 - 11:56
Thanks a lot for your help !
Now I solved it - the handle to the responsible OCAF application was deleted somewhere before the save operation. Mea culpa...