CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   find the hanging pointer ... (http://www.cfd-online.com/Forums/openfoam-programming-development/83232-find-hanging-pointer.html)

mvoss December 20, 2010 12:09

find the hanging pointer ...
 
hi,

this is concerning the very general question about how to find a hanging pointer.
I am working on a MultiRegion-Solver, so i was starting from chtMultiRegionsFoam.

I followed the pattern in the solver
by addressing the pointers first with the appropriate size of the meshRegion with
Code:

PtrList<basicPsiThermo> thermoFluid(fluidRegions.size());
and then setting the pointerlists to the IOobjects by e.g.
Code:


Info<< "    Adding to KFluid\n" << endl;
                KFluid.set
                (
                    i,
                    new volScalarField
                    (
                        IOobject
                        (
                            "K",
                            runTime.timeName(),
                            fluidRegions[i],
                            IOobject::NO_READ,
                            IOobject::NO_WRITE
                        ),
                        thermoFluid[i].Cp()*thermoFluid[i].alpha()
                    )
                );

and finally use the local-"region"-variables in the normal manner.
Code:

fvScalarMatrix tEqn
        (
            -fvm::laplacian(K, T)
        );
        tEqn.relax();
        TEqnResidual = tEqn.solve().initialResidual();

Then i added the "solve"-part by including some working header-files.
The code is compiling but i am receiving an ERROR about: hanging pointer, cannot dereference .

So. How to solve this since there are plenty of pointers.
Is there a way to find the "bad" one? I just need some general advice where to search or how to look at that problem ... and maybe solving it the next time on my own. ;)

Thanks in advance...

neewbie

l_r_mcglashan December 21, 2010 06:43

When I had that error it was always because I got the range of a 'for' loop incorrect and I was trying to access an element in the pointer list that didn't exist. I would check the rangess of the loops you have in your program.

mvoss January 3, 2011 04:35

hi,
thanks a lot. I did as you said and ended up in deleting EVERYTHING not necessary ... ive made a similar mistake by commenting over more than one line. took me a while to riddle that one out.

neewbie


All times are GMT -4. The time now is 05:37.