CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

PtrList of surfaceScalarFields -> destructor problem?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By cliffoi

Reply
 
LinkBack Thread Tools Display Modes
Old   October 26, 2011, 08:51
Default PtrList of surfaceScalarFields -> destructor problem?
  #1
Member
 
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 40
Rep Power: 8
dohnie is on a distinguished road
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_);
This throws an error at the end of the run:
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
Invalid pointer? Actually I thought the PtrList had its own destructor that would take care of everything. If not, what does my constructor have to do?

Code:
myClass::~myClass()
{
    for (label i=9; i>=0; i--)
    {
        delete[] myPtrList_(i);
    }
}
does not work.
dohnie is offline   Reply With Quote

Old   October 26, 2011, 09:12
Default
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
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.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   October 28, 2011, 07:46
Default
  #3
Member
 
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 40
Rep Power: 8
dohnie is on a distinguished road
Thank you,
I have not found it yet, but I keep on searching....
dohnie is offline   Reply With Quote

Old   October 28, 2011, 17:16
Default
  #4
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 91
Rep Power: 8
cliffoi is on a distinguished road
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.
luiscardona likes this.
cliffoi is offline   Reply With Quote

Reply

Tags
destructor, ptrlist

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IOField<List<scalar > > heavy_user OpenFOAM 1 June 19, 2012 16:29
STL -> GMSH -> OpenFOAM eric.m.tridas OpenFOAM 7 September 7, 2011 12: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 12:46


All times are GMT -4. The time now is 13:54.