I’m not quite sure how to phrase a good question here but I have to ask someone! My mind has melted at this point.
I have a plugin that sometimes works beautifully and other times seemingly randomly fails. There is a call to LoadLibraryEx in a third party file that returns NULL although the path exists. The strange thing is that it works sometimes and then, with no changes I am aware of, stop working again. Also, sometimes the errors pop when one pushes play and sometimes when you stop playing…
The plugin in question is this: GitHub - ORNL-Modelica/UnrealEngine-FMIPlugin
The offending line appears to be: Line 138 of the 3rd party code FMU.cpp
m_libraryHandle = LoadLibraryEx(libPath.c_str(), NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
Below is the error that occurs when I push play.
I wish I could provide more of an idea of what is going on but I can’t quite figure what madness is going on… Perhaps some memory being tied up magically somehow?
Out of curiosity, is there any pattern to when it works vs. not? (Running in a Visual Studio debugger versus running launched from clicking a .uproject
file in explorer, etc.)
Sort of wondering if the search directories might differ there depending on how you’re running it, in which case it might sometimes not be finding the library to load?
It really doesn’t seem like there is a pattern. Each sometimes works and sometimes doesn’t… crashing more often than not. One of the strange things that I didn’t mention are that on my own computer I have some more FMUs (basically compiled simulations - i.e., the dll is within this FMU object).
Some FMUs created with Matlab never crashes that I can recall, but ones created with Dymola sometimes crash and sometimes don’t…
I would think if there was a fundamental issue with the FMU then it would always crash… not just when the wind blows from the south at 10 knots…
No one has created an issue about this on the github site (I am the dev) so I’m not sure if this is just something going fishy with my setup… 
Where’s the library it’s trying to load, in relation to your plugin?
It can be anywhere, it is specified by the user (See 0:08 FMI in Unreal Engine with the FMI-Plugin - YouTube). I have tried outside the git repo, in the git repo, and within the content directory…
I didn’t see these issues back in October 7 when I last modified the plugin… I guess there was a UE 4.27.1 and 4.27.2 though… maybe there was some change between 4.26 and 4.27 that is somehow causing issues…
I think the takeaway I am getting is that it may behoove me to try to migrate to 5.0 and see if that fixes things… Worth a shot. I’ll give it a go.
Yeah, I think probably what I would do next is put a breakpoint just after LoadLibraryEx
, make it conditional on the result being nullptr
, and then when it hit the breakpoint see what things in that routine itself looked like, state-wise.
It might not give any pointers towards a solution, but… I’ve seen weirder things than there being some scenario where an invalid path got passed in from elsewhere.
Been working on this more… The takeaways so far is that some of the issues are due to:
- unzip tool not being on a path (though it appearing like it was as the FMU was getting unzipped somehow… very strange) - This was the major cause of issues… Additional messaging in the log output is being added.
- Issues with autolooping causing (we think) issues with dlls that don’t have access. Unclear if the underlying FMI interface tool has the tools to handle this. But that is ok for now… will add an issue in the repo.
- Changed the extracted FMU to have appended the actor name to avoid having multiple actors using the same FMU files (this may not have been an issue but it seems like a better idea)
- Still some Symbol not found errors that randomly occur when a simulation is stopped… Big mystery here… oh well
- And… still haven’t ruled out with the tools that originally created the FMUs (i.e., the dlls) as the source of most of the problems… but that is really out of my hands.
I think there is enough progress with some of those changes that I am calling this issue CLOSED… afterall… this is still a prototype :
1 Like
Glad you’ve made progress!