Graceful exit with DynamicNumericDiffCostFunction?

50 views
Skip to first unread message

Rodney Hoskinson

unread,
Jan 29, 2015, 7:40:31 PM1/29/15
to ceres-...@googlegroups.com
I can't work out why the attached program doesn't exit cleanly. It is like HelloworldNumericDiff but trying to use DynamicNumericDiffCostFunction.

The program runs correctly but at the end it seems that the Problem::~Problem() destructor fails when it tries to delete the pointer to ceres::internal::ProblemImpl, with a _Block_Type_Is_Valid (pHead->nBlockUse) error at line 76 in scoped_ptr.h.

I only get this problem with the DynamicNumericDiffCostFunction, which I wish to use for my application. No problem with plain NumericDiffCostFunction (e.g. HelloworldNumericDiff  exits clean).

I'm using the 1.10.0 build on Win7 64bit.

Rodney






testCeresDyn.cpp

Sameer Agarwal

unread,
Jan 29, 2015, 8:24:14 PM1/29/15
to ceres-...@googlegroups.com
you are creating the CostFunction object on the stack.
Problem by default will take ownership of the cost_function you pass to it, and try to delete it upon destruction. so here, the cost function is getting deleted off the stack before the Problem destructor gets called at which point, well trouble happens.

Changing the code as follows fixes the problem.

DynamicNumericDiffCostFunction<DynamicCostFunctor, CENTRAL> * cost_function =
            new DynamicNumericDiffCostFunction<DynamicCostFunctor, CENTRAL> (
                new DynamicCostFunctor);
cost_function->AddParameterBlock(1);
cost_function->SetNumResiduals(1);
problem.AddResidualBlock(cost_function, NULL, &x);

Sameer



--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/73d62f92-15a7-40b2-b058-dbdfadb697cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rodney Hoskinson

unread,
Jan 29, 2015, 8:56:01 PM1/29/15
to ceres-...@googlegroups.com
Sameer  

Thanks for setting me straight on this! The code snippets in the docs currently show NumericDiffCostFunction being created on the heap, DynamicNumericDiffCostFunction on the stack. 

Cheers

Rodney

Sameer Agarwal

unread,
Jan 29, 2015, 9:53:22 PM1/29/15
to ceres-...@googlegroups.com

Happy to help. I will make sure that the snippets in the docs make sense.


Reply all
Reply to author
Forward
0 new messages