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

Related pages

OCC6.1 Memory Manager

mz's picture
Forums: 

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 !

Bearloga's picture

Do you use OCC in one thread only? If no then try using reentrant mode of memory manager (MMGT_REENTRANT).

mz's picture

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 ;
}
}

mz's picture

Sorry, I didn't response to your question itself: There is one thread only.

Fotis Sioutis's picture

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

mz's picture

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()

Fotis Sioutis's picture

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

mz's picture

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?

Bearloga's picture

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.

mz's picture

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...

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.