When I run the C++ code generated by Matlab Coder, different errors ("invalid pointer," "invalid size," etc.) occur only under a small subset of chosen parameter values.

조회 수: 6 (최근 30일)
When I run the C++ code generated by Matlab Coder, it works correctly most of the time.
However, when some parameter values are used, errors occur, and these errors are often different. Sometimes it is "munmap_chunk(): invalid pointer," sometimes it is "double free or corruption (out)," sometimes it is "segmentation fault," and sometimes it is "free(): invalid size."
The errors occur in a subfunction whose output consists of some cell arrays of variable sizes. In most cases when errors occur, the code can run to the end of this subfunction.
Why does this happen? What should I do to resolve this problem?
  댓글 수: 1
Raghu Boggavarapu
Raghu Boggavarapu 2025년 3월 27일
Could you try generating MEX and run the MEX with the same arguments you are passing to the generated code and see if it reports any errors?

댓글을 달려면 로그인하십시오.

답변 (1개)

Marie Anna NOVIELLO
Marie Anna NOVIELLO 2025년 3월 27일
The errors you're encountering, such as "munmap_chunk(): invalid pointer", "double free or corruption (out)", "segmentation fault", and "free(): invalid size", typically indicate issues related to memory management in C++ code, particularly with how memory is allocated, deallocated, or accessed.
Check dynamic memory allocation or look at the generated C++ code.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by