summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
5d6e41c)
Previous assumptions of unloadFMU was that there was a valid C-level
pointer to cleanup and pass to the FMU model's cleanup functions.
However, if only loadFMU is called prior to unloadFMU, then JVM would
crash with an access violation exception. I introduced a boolean for
instantiated to keep track of this to ensure we avoid future crashes if
unloadFMU is called directly after loadFMU.
gitlab #13
Change-Id: Idef742d6805e856617c3c95c0bb751d8a48caa0d
* @throws FMILException
*/
private int fmuN = 0;
* @throws FMILException
*/
private int fmuN = 0;
- private boolean fmuLoaded = false;
+ private boolean instantiated = false;
public void loadFMUFile(String path) throws FMILException {
if (!Files.exists(Paths.get(path)))
public void loadFMUFile(String path) throws FMILException {
if (!Files.exists(Paths.get(path)))
for(int i=0;i<variableNames.length;i++) {
variableMap.put(variableNames[i], variableReferences[i]);
}
for(int i=0;i<variableNames.length;i++) {
variableMap.put(variableNames[i], variableReferences[i]);
}
+
+ instantiated = false;
} catch (UnsatisfiedLinkError err) {
throw new FMILException(UNSATISFIED_LINK, err);
} catch (Exception e) {
} catch (UnsatisfiedLinkError err) {
throw new FMILException(UNSATISFIED_LINK, err);
} catch (Exception e) {
try {
int ret = instantiateSimulation_(getModelIDNew());
try {
int ret = instantiateSimulation_(getModelIDNew());
LOGGER.warn("Function return value != OK, an exception should have been thrown from native code!");
LOGGER.warn("Function return value != OK, an exception should have been thrown from native code!");
+ } else {
+ instantiated = true;
+ }
} catch (FMILException e) {
throw e;
} catch (UnsatisfiedLinkError err) {
} catch (FMILException e) {
throw e;
} catch (UnsatisfiedLinkError err) {
try {
unlockFMUDirectory();
try {
unlockFMUDirectory();
+
+ // Many FMUs will not correctly clean-up during unload if the simulation isn't instantiated
+ // Essentially we'd likely be passing an invalid pointer to the FMU to cleanup, causing native c-level crashes.
+
+ if(instantiated) {
int ret = unloadFMU_(getModelIDNew());
if(ret != OK)
LOGGER.warn("Function return value != OK, an exception should have been thrown from native code!");
int ret = unloadFMU_(getModelIDNew());
if(ret != OK)
LOGGER.warn("Function return value != OK, an exception should have been thrown from native code!");
}
removeFMUDirectoryContents();
}
removeFMUDirectoryContents();