ORNL-Modelica / UnrealEngine-FMIPlugin

27 stars 5 forks source link

Add files via upload #16

Closed lewinj closed 3 years ago

lewinj commented 3 years ago

I added code to A_FMU.h, A_FMU.cpp, and FMU2.h to destroy and free the instances of the fmu on end of play.

greenwoodms06 commented 3 years ago

A couple comments:

greenwoodms06 commented 3 years ago

@lewinj I was discussing with @tnorby and instead of changing the FMU2.cpp file, you should be able to just add the line in the EndPlay function. This will call the destructor built into the FMU class (the ~FMU2 is the destructor).

delete mFmu;

http://www.cplusplus.com/reference/new/operator%20delete/ The example there shows "new" which calls the constructor and allocates memory for the pointer, and "delete".

// operator delete example
#include <iostream>     // std::cout
struct MyClass {
  MyClass() {std::cout <<"MyClass constructed\n";}
  ~MyClass() {std::cout <<"MyClass destroyed\n";}
};
int main () {
  MyClass * pt = new (std::nothrow) MyClass;
  delete pt;    // implicitly calls ::operator delete(pt)
  return 0;
}
lewinj commented 3 years ago

I wasn't able to call the ~FMU2 function in end of play, I probably was doing it wrong. Also, I was getting errors without that semicolon. I'll redo the code and reupload the pull request. Sorry about A_FMU, I'm still new to GitHub.