Skip to content
New issue

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

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

Already on GitHub? # to your account

Unity Crash when loading fmi2DoStep and fmi2SetReal #11

Open
dbsrn0125 opened this issue Dec 1, 2024 · 3 comments
Open

Unity Crash when loading fmi2DoStep and fmi2SetReal #11

dbsrn0125 opened this issue Dec 1, 2024 · 3 comments

Comments

@dbsrn0125
Copy link

Hi. Thanks for the Addon.

It works when I try to Simulate FMU which I made with Simulink, but when I try to simulate FMU which I made with OpenModelica,
Unity Suddenly crashed and shut down.

I tried annotation line by line, and I found that
fmi2DoStep = getFunc(dll, "fmi2DoStep");
fmi2SetReal = getFunc(dll, "fmi2SetReal");

Those two line on FMI2.cs make Unity crash.

I'm not an expert in this side but I wonder why other functions can be got by dll while those two can't.

Can you fix this for me or give me some advice to handle this problem?

@t-sommer
Copy link
Contributor

t-sommer commented Dec 2, 2024

Can you share an FMU to reproduce the problem?

@dbsrn0125
Copy link
Author

dbsrn0125 commented Dec 2, 2024

Hello! Thanks for your comment!
Github doesn't support fmu type so I changed file type to Zip and uploaded it.
test.zip

Also here is my OMedit Options capture.
image
image

I guess there are some problems in OpenModelica fmu or my OMedit Settings, since Simulink FMU works on this addon(still need to change some settings like editting Unity fixed time step to 0.001 and change script's Time.time to Time.timeAsDouble)

image
Those three comments are where make Unity crash in that fmu. I checked several times. If I uncomment any line out of those three comments, Unity crash.

Thanks a lot again, and I appreciate for your work!
I tried my best to figure it out but I'm not familiar with it.
If there are any problem with my OMedit settings or fmu, let me know

Below is modelica code of the fmu just in case you might need it.
'''
model test
type Height=Real(unit="m");
type Velocity=Real(unit="m/s");
parameter Real e=0.8 "Coefficient of restitution";
parameter Height h0=1.0 "Initial height";
Height h "Height";
Velocity v(start=0.0, fixed=true) "Velocity";
initial equation
h = h0;
equation
v = der(h);
der(v) = -9.81;
when h<0 then
reinit(v, -e*pre(v));
end when;
end test;
'''

@t-sommer
Copy link
Contributor

t-sommer commented Dec 3, 2024

I can successfully simulate the FMU in FMPy and fmusim. Unfortunately I don't have access to a Unity license at the moment, so I can't debug it in Unity.

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

No branches or pull requests

2 participants