OSQP in C++ - Warm-start pointer/reference problems

Hello!

I’m facing some problems using warm-start and the C++ interface.

I need to use create the solver structures and pass them to a function inside a function where the solver is initialized, solve the QP problem, return from the function and then solve the second QP problem. It’s a secuence of QP problems.

I checked the warmstart example. This image resumes my code structure. I’m starting the structures the same way the example does.

And this image show the function in my code.

The first iteration it’s OK and return a solution, but the second problem throws error 7(Solver workspace not initialized) and a segmentation fault.

I’m pretty sure it must be a pointer/refence issue, but I can’t figure out. Can you help me?

I’m thinking about changing some solver’s functions, but it’s not the idea.

Thank you in advance.

Since the pointer work changes inside the function, you should pass to osqpSW a pointer to it. In particular, the corresponding argument of osqpSW should be OSQPWorkspace **work, which will also modify the function calls as follows:

exitflag = osqp_setup(work, data, settings);
osqp_update_lin_cost(*work, h);
osqp_update_upper_bound(*work, c);
osqp_solve(*work);