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

rtwsfcnfmi FMU containing an S-Function packed in MATLAB 2022b crashes MATLAB #475

Open
benplay2 opened this issue Apr 17, 2024 · 1 comment
Labels
RTWSFCN This issue is related to the S-Function based FMU export

Comments

@benplay2
Copy link

benplay2 commented Apr 17, 2024

Problem

FMUs packaged with rtwsfcnfmi.tlc from FMIKit 3.1 in MATLAB 2022b crash MATLAB when they are executed.

image

After a little debugging, I discovered that the error occurs in fmi2functions.c fmi2SetReal():
image

Replication

I created a test function to demonstrate the error state. Please see the zip file. Here's a snippet of the code:

% Perform a simple test to demonstrate an error state of FMIKit which
% causes MATLAB to crash.
% 
% From my testing with FMIKit v3.1, usage of the FMU created with 2021b
% works properly, but the one created using 2022b crashes MATLAB.

load_system(model)

cs = getActiveConfigSet(gcs);
switchTarget(cs, 'rtwsfcnfmi.tlc', []);

set_param(model, 'GenerateReport', 'off');
set_param(model, 'FMIType', 'CoSimulation');

set_param(model, 'SolverType', 'Fixed-step');

set_param(model, 'LoadBinaryMEX', loadSfunctionBinary); %Even if no s-Function in "model", this causes a crash when simulated (2022b)


slbuild(model);

close_system(model, 0);

%Now, open a new simulink model and create an FMU block of this and try to
%simulate. I used the built-in Simulink FMU block

fmikitErrorExamples.zip

Workaround

Using MATLAB 2021b to create the FMU seems to resolve the problem. Was there an S-Function API change between the versions?

System details:

  • Windows 10
  • MATLAB Version: 9.13.0.2399474 (R2022b) Update 7
  • Compiler: Visual Studio 2017
  • FMIKit version 3.1
@t-sommer t-sommer added the RTWSFCN This issue is related to the S-Function based FMU export label May 8, 2024
@t-sommer
Copy link
Contributor

t-sommer commented May 8, 2024

Thanks for sharing the example, @benplay2. There seems to be an internal API change in 2022b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RTWSFCN This issue is related to the S-Function based FMU export
Projects
None yet
Development

No branches or pull requests

2 participants