Segmentation violation in Matlab using Template-Interface

Hi,

I updated to the latest ACADOS version for the first time since mid of December 2020 (https://github.com/acados/acados/commit/e4873172586a55e626dba3d5cf07648b68767bf4) and now I get a segmentation violation with code that perfectly worked before:

Stack Trace (from fault):
[ 0] 0x0000000000000000 <unknown-module>+00000000
[ 1] 0x00007fdd789ac9c6 /home/martin/mppoav/acados_M2410/build/ocp_set.mexa64+00014790 mexFunction+00009734

Any ideas what has changed in ocp_set and could result in a segfault?

There are no additional error messages in Matlab or on the console. The violation only occurs when I use the Template-Solver for Matlab, it works with the normal Matlab-Interface. But since I use the Template-Solver in a C++ application I also need to test it in Matlab.

BR
Martin

Hi Martin,

thanks for reporting this!
Actually nothing changed in the ocp_set function between the latest acados version and 0.1.4.

However, there were a few changes in the template based interface.
It might be that something needs to be adapted for the interaction of the templated solver with Matlab.

Just to check:
Did you remove the Matlab build folder in your Matlab example folder?

If so:
In which call to ocp_set does this happen?
which field are you passing?

If you can share the code to reproduce the error with me that might be the easiest.

Feel free to follow up with a private message.

Best,
Jonathan

Hi Jonathan,

Did you remove the Matlab build folder in your Matlab example folder?

Yes, I deleted it.

it seems that setting the parameters for the terminal stage is the problem. In the final loop iteration ocp.set() crashes Matlab:

for ii = 0 : mpcParams.N
    
    ...
    ocp.set('p', p, ii);
end

BR
Martin

Hi Martin,

it is now clear to me what the issue is.
It was introduced here, when adding the option to have a separate cost term at the initial stage: https://github.com/acados/acados/pull/684
This will make the solver crash with
ocp.set('p', p, N-1);
if a cost module other than linear least squares are used.

Unfortunately, I will need a bit of time to fix it.
The “easiest” solution I see is to add a third phase in the Matlab interface.
For reference, e.g. here: https://github.com/acados/acados/blob/master/interfaces/acados_matlab_octave/ocp_set.c#L123-L124

I will update this topic as soon as I have a fix that you can test with your example.

Best,
Jonathan

Hi Jonathan,

yes, you are right, it’s actually not the final loop iteration in my example above, but the one before.

BR
Martin

Hi Martin,

I thought about that again, and there was a relatively easy fix.
Can you test your code with the branch corresponding to this PR? https://github.com/acados/acados/pull/700

Best,
Jonathan

Hello Jonathan,

thanks a lot :+1:, your PR solves the problem.

BR
Martin