|
[Sponsors] |
PtrList of surfaceScalarFields -> destructor problem? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 26, 2011, 09:51 |
PtrList of surfaceScalarFields -> destructor problem?
|
#1 |
Member
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 41
Rep Power: 17 |
Hello everybody,
I have a class that contains several surfaceScalarFields which I want to loop over. Therefore I set up a PtrList in the constructor: Code:
myPtrList_(10); // is a PtrList<surfaceScalarField> myPtrList_.set(0, &FieldA_); // pointer 0 should point to surfaceScalarField FieldA_ myPtrList_.set(1, &FieldB_); // and so on... myPtrList_.set(9, &FieldJ_); Code:
End of run. *** glibc detected *** lookupRiemannFoam: free(): invalid pointer: 0x00007fff5d62f9c8 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x73286)[0x7f712a62e286] /lib64/libc.so.6(cfree+0x6c)[0x7f712a63302c] lookupRiemannFoam[0x451dc3] lookupRiemannFoam[0x4413f1] /lib64/libc.so.6(__libc_start_main+0xfd)[0x7f712a5d9b7d] lookupRiemannFoam[0x428639] ======= Memory map: ======== 00400000-004da000 r-xp 00000000 00:15 384262308 Code:
myClass::~myClass() { for (label i=9; i>=0; i--) { delete[] myPtrList_(i); } } |
|
October 26, 2011, 10:12 |
|
#2 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
Some of your fields (FieldA_, etc) might've gone out of scope and destroyed themselves, in which case, you'd have an invalid pointer that PtrList is trying to free.
Your description lacks context - it's hard to judge where the problem is, because it's definitely not in the lines that you describe. |
|
October 28, 2011, 08:46 |
|
#3 |
Member
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 41
Rep Power: 17 |
Thank you,
I have not found it yet, but I keep on searching.... |
|
October 28, 2011, 18:16 |
|
#4 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
It does look like your surfaceScalarFields are going out of scope somewhere.
Important: If you are looking to reference fields from a PtrList, you need to be careful since PtrList automatically destructs the objects you assign to it with the ::set member function. Rather use UPtrList in your case since it will not destruct your fields when it goes out of scope. |
|
Tags |
destructor, ptrlist |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
IOField<List<scalar > > | heavy_user | OpenFOAM | 3 | July 26, 2017 05:45 |
STL -> GMSH -> OpenFOAM | eric.m.tridas | OpenFOAM | 7 | September 7, 2011 13:06 |
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? | will.logie | OpenFOAM Programming & Development | 1 | February 16, 2011 21:52 |
1.7.x -> buoyantPimpleFoam -> hRhoThermo -> incompressible and icoPoly3ThermoPhysics? | will.logie | OpenFOAM | 0 | December 16, 2010 08:08 |
CAD -> gMsh -> enGrid -> OpenFOAM Problem | AlGates | OpenFOAM | 7 | August 6, 2010 13:46 |