Closed Nils12345678901234567 closed 7 hours ago
Can you provide a piece of code to reproduce this issue?
If you modify the test LogWhenVariableCannotBeSet
like this:
[Test]
public void LogWhenVariableCannotBeSet()
{
var spyCallback = new SpyCallback();
using var model = Model.Load(TestTools.GetFmuPath("BouncingBall.fmu"));
using var instance = model.CreateCoSimulationInstance("my name", spyCallback);
try
{
GC.Collect(); // Force garbage collection here to reproduce bug
instance.WriteReal((model.Variables["v_min"], 1));
}
Note: The test will not fail, it will never finish execution. You have to look in the output window to see the error message.
I tried to reproduce with the test FeedthroughReferenceScenario
as well but that didi not work. I suspect that the 'Feedthrough.fmu' fmu never calls any callbacks. A similar test using BouncingBall.fmu would probably show the problem.
If the local variable functions
in the constructor of the Callbacks
class is changed to a member variable of the Callbacks-class like shown below this should fix the problem.
class Callbacks : IDisposable
{
private FMI2.fmi2CallbackFunctions functions;
public Callbacks(Instance instance, ICallbacks cb)
{
Instance = instance;
CB = cb;
handle = GCHandle.Alloc(this);
functions = new FMI2.fmi2CallbackFunctions
{
logger = LoggerCallback,
allocateMemory = Marshalling.AllocateMemory,
freeMemory = Marshalling.FreeMemory,
stepFinished = StepFinishedCallback,
componentEnvironment = GCHandle.ToIntPtr(handle)
};
Thank you. The suggested change is implemented in the current version.
After running my simulation loop for a short while (setting inputs - AdvanceTime - reading outputs)the program crashes with this error:
Turns out that this happens when the garbage collector kicks in. If I call GC.Collect in my simulation loop I get the error immediately.
If I debug the program in Visual Studio it catches a
ExecutionEngineException
with no call stack.