Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATLAB not responding when running update() #5

Closed
HosameldinMohamed opened this issue Feb 28, 2022 · 5 comments
Closed

MATLAB not responding when running update() #5

HosameldinMohamed opened this issue Feb 28, 2022 · 5 comments

Comments

@HosameldinMohamed
Copy link

HosameldinMohamed commented Feb 28, 2022

I have osqp installed via robotology-superbuild. When I tried to run the OSQP LASSO example. MATLAB stops responding and I need to force-restart it.

The line responsible for the issue is this

prob.update('q', q_new);

All the other lines work as expected. Even the solve() function.

I tested the same example script with the official binary installation, and it works without issues.

The terminal throws this error

double free or corruption (out)
@traversaro
Copy link
Contributor

traversaro commented Feb 28, 2022

Thanks for the report. At a first glance it is something similar to the issue fixed by osqp/osqp-matlab#34 but for the lines related to update.

@traversaro
Copy link
Contributor

I.e. we need to change mxFree to c_free in https://github.com/osqp/osqp-matlab/blob/7a9057c89dff9da9abeeb328d99e6bfda9adcefd/osqp_mex.cpp#L456 and in the subsequent lines.

@traversaro
Copy link
Contributor

traversaro commented Mar 1, 2022

I will soon prepare a PR, but in the meanwhile this is the patch with the changes required for osqp-matlab. With this changes, I am able to run the testsuite (removing codegen that is intentionally not supported):

diff --git a/osqp_mex.cpp b/osqp_mex.cpp
index 032877b..5506e1d 100755
--- a/osqp_mex.cpp
+++ b/osqp_mex.cpp
@@ -453,13 +453,13 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         }
 
         // Free vectors
-        if(!mxIsEmpty(q)) mxFree(q_vec);
-        if(!mxIsEmpty(l)) mxFree(l_vec);
-        if(!mxIsEmpty(u)) mxFree(u_vec);
-        if(!mxIsEmpty(Px)) mxFree(Px_vec);
-        if(!mxIsEmpty(Ax)) mxFree(Ax_vec);
-        if(!mxIsEmpty(Px_idx)) mxFree(Px_idx_vec);
-        if(!mxIsEmpty(Ax_idx)) mxFree(Ax_idx_vec);
+        if(!mxIsEmpty(q)) c_free(q_vec);
+        if(!mxIsEmpty(l)) c_free(l_vec);
+        if(!mxIsEmpty(u)) c_free(u_vec);
+        if(!mxIsEmpty(Px)) c_free(Px_vec);
+        if(!mxIsEmpty(Ax)) c_free(Ax_vec);
+        if(!mxIsEmpty(Px_idx)) c_free(Px_idx_vec);
+        if(!mxIsEmpty(Ax_idx)) c_free(Ax_idx_vec);
 
         // Report errors (if any)
         switch (exitflag) {
@@ -513,8 +513,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         osqp_warm_start(osqpData->work, x_vec, y_vec);
 
         // Free vectors
-        if(!mxIsEmpty(x)) mxFree(x_vec);
-        if(!mxIsEmpty(y)) mxFree(y_vec);
+        if(!mxIsEmpty(x)) c_free(x_vec);
+        if(!mxIsEmpty(y)) c_free(y_vec);
 
         return;
     }
@@ -544,7 +544,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         osqp_warm_start_x(osqpData->work, x_vec);
 
         // Free vectors
-        if(!mxIsEmpty(x)) mxFree(x_vec);
+        if(!mxIsEmpty(x)) c_free(x_vec);
 
         return;
     }
@@ -574,7 +574,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         osqp_warm_start_y(osqpData->work, y_vec);
 
         // Free vectors
-        if(!mxIsEmpty(y)) mxFree(y_vec);
+        if(!mxIsEmpty(y)) c_free(y_vec);
 
         return;
     }
diff --git a/run_osqp_tests.m b/run_osqp_tests.m
index 29d9d18..9efd6f6 100644
--- a/run_osqp_tests.m
+++ b/run_osqp_tests.m
@@ -4,8 +4,8 @@ import matlab.unittest.TestSuite;
 unittest_dir = fullfile(osqp_path, 'unittests');
 suiteFolder = TestSuite.fromFolder(unittest_dir);
 
-% Solve individual test file
-%suiteFolder = TestSuite.fromFile('unittests/dual_infeasibility_tests.m');
+% Remove codegen tests
+newSuite = selectIf(suite,HasName(ContainsSubstring('pAtH','IgnoringCase',true)))
 
 % Run all suite
 result = run(suiteFolder);

@traversaro
Copy link
Contributor

The upstream PR has been updated with additional fixes that solve this issue (see osqp/osqp-matlab@09faf01).

@traversaro
Copy link
Contributor

Fixed by #6 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants