From 9d05e918367fc402cc1646f5b786099b0ec26389 Mon Sep 17 00:00:00 2001 From: JoKircher Date: Wed, 1 Mar 2023 09:57:41 +0100 Subject: [PATCH 1/4] some work on the issue --- src/FMI2/ext.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index 71d4e92..7fd301d 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -489,6 +489,23 @@ function fmi2Unload(fmu::FMU2, cleanUp::Bool = true) @warn "Cannot delete unpacked data on disc. Maybe some files are opened in another application." end end + # println(typeof(fmu)) + # stateRef = pointer_from_objref(fmu) + # println(stateRef) + # val = nothing + # refVal = Ptr{nothing}(val) + # stateRef = refVal + # println(typeof(fmu)) + # fmu = stateRef + # fmu = nothing + fmu = removeStruct(fmu) +end + +function removeStruct(fmu) + z = Ref(nothing) + fmu = z[] + println(fmu) + nothing end """ From 93616533e14fca27def5c584ea31970e95197fb1 Mon Sep 17 00:00:00 2001 From: JoKircher Date: Wed, 1 Mar 2023 09:57:41 +0100 Subject: [PATCH 2/4] some work on the issue --- src/FMI2/ext.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index 54a9b2f..e5153b2 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -528,6 +528,23 @@ function fmi2Unload(fmu::FMU2, cleanUp::Bool = true) @warn "Cannot delete unpacked data on disc. Maybe some files are opened in another application." end end + # println(typeof(fmu)) + # stateRef = pointer_from_objref(fmu) + # println(stateRef) + # val = nothing + # refVal = Ptr{nothing}(val) + # stateRef = refVal + # println(typeof(fmu)) + # fmu = stateRef + # fmu = nothing + fmu = removeStruct(fmu) +end + +function removeStruct(fmu) + z = Ref(nothing) + fmu = z[] + println(fmu) + nothing end """ From 47148df27a55717875d41302c18c8d5bc95678d0 Mon Sep 17 00:00:00 2001 From: JoKircher <79573182+JoKircher@users.noreply.github.com> Date: Wed, 5 Apr 2023 11:33:57 +0200 Subject: [PATCH 3/4] remove unneeded struct --- src/FMI2/ext.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index 741538c..ee284a7 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -538,6 +538,7 @@ function fmi2Unload(fmu::FMU2, cleanUp::Bool = true) # fmu = stateRef # fmu = nothing fmu = removeStruct(fmu) + return nothing end function removeStruct(fmu) @@ -547,12 +548,6 @@ function removeStruct(fmu) nothing end -function removeStruct(fmu) - z = Ref(nothing) - fmu = z[] - println(fmu) - nothing -end """ fmi2SampleJacobian(c::FMU2Component, From 99ef7615c7b23e7cb4dbbcdaae1e6de4ef7179b6 Mon Sep 17 00:00:00 2001 From: JoKircher <79573182+JoKircher@users.noreply.github.com> Date: Thu, 20 Jul 2023 10:16:17 +0200 Subject: [PATCH 4/4] remove pointers to freed segements --- src/FMI2/ext.jl | 81 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index aa0b81e..d200cd2 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -531,24 +531,75 @@ function fmi2Unload(fmu::FMU2, cleanUp::Bool = true) @warn "Cannot delete unpacked data on disc. Maybe some files are opened in another application." end end - # println(typeof(fmu)) - # stateRef = pointer_from_objref(fmu) - # println(stateRef) - # val = nothing - # refVal = Ptr{nothing}(val) - # stateRef = refVal - # println(typeof(fmu)) - # fmu = stateRef - # fmu = nothing - fmu = removeStruct(fmu) + unloadBinary(fmu) + fmu.libHandle = nothing + # fmu.cGetVersion = nothing return nothing end -function removeStruct(fmu) - z = Ref(nothing) - fmu = z[] - println(fmu) - nothing +function unloadBinary(fmu::FMU2) + fmu.cInstantiate = nothing + fmu.cGetTypesPlatform = nothing + fmu.cGetVersion = nothing + fmu.cFreeInstance = nothing + fmu.cSetDebugLogging = nothing + fmu.cSetupExperiment = nothing + fmu.cEnterInitializationMode = nothing + fmu.cExitInitializationMode = nothing + fmu.cTerminate = nothing + fmu.cReset = nothing + fmu.cGetReal = nothing + fmu.cSetReal = nothing + fmu.cGetInteger = nothing + fmu.cSetInteger = nothing + fmu.cGetBoolean = nothing + fmu.cSetBoolean = nothing + + fmu.cGetString = nothing + fmu.cSetString = nothing + + if fmi2CanGetSetState(fmu.modelDescription) + fmu.cGetFMUstate = nothing + fmu.cSetFMUstate = nothing + fmu.cFreeFMUstate = nothing + end + + if fmi2CanSerializeFMUstate(fmu.modelDescription) + fmu.cSerializedFMUstateSize = nothing + fmu.cSerializeFMUstate = nothing + fmu.cDeSerializeFMUstate = nothing + end + + if fmi2ProvidesDirectionalDerivative(fmu.modelDescription) + fmu.cGetDirectionalDerivative = nothing + end + + # CS specific function calls + if fmi2IsCoSimulation(fmu.modelDescription) + fmu.cSetRealInputDerivatives = nothing + fmu.cGetRealOutputDerivatives = nothing + fmu.cDoStep = nothing + fmu.cCancelStep = nothing + fmu.cGetStatus = nothing + fmu.cGetRealStatus = nothing + fmu.cGetIntegerStatus = nothing + fmu.cGetBooleanStatus = nothing + fmu.cGetStringStatus = nothing + end + + # ME specific function calls + if fmi2IsModelExchange(fmu.modelDescription) + fmu.cEnterContinuousTimeMode = nothing + fmu.cGetContinuousStates = nothing + fmu.cGetDerivatives = nothing + fmu.cSetTime = nothing + fmu.cSetContinuousStates = nothing + fmu.cCompletedIntegratorStep = nothing + fmu.cEnterEventMode = nothing + fmu.cNewDiscreteStates = nothing + fmu.cGetEventIndicators = nothing + fmu.cGetNominalsOfContinuousStates= nothing + end end