From: Ola R. T. <ol...@si...> - 2010-09-14 20:02:55
|
I've looked further into the code and found some bugs and potential problems. The first one is in FGFDMExec's destructor. It has a try/catch block, in which it checks for Root == 0, and if so, deletes the object pointed to by the static pointer "master". Root can never be zero, so this part is never executed, and the FGPropertyManager object is never deleted. Root is never zero because it's set to be the same as master, in FGFDMExec's constructor right after the line master = new FGPropertyManager();. So to try to fix this I added a member variable "bool GotMaster" being set to true if Root was NULL in FGFDMExec's constructor (thus creating the master object), and replaced the check for Root == 0 to check if this flag is true. Then master gets deleted. Also I had to add "master = NULL;" after deleting it. This actually fixes my issue. I can create a FGFDMExec object, delete it again, and create another one, and so on. :-) But then I tried to run several aircraft at the same time. This works ok until I try deleting one of them, which causes a crash. I think this is basically caused because the master pointer is static and thereby shared by all the FGFDMExec objects. So then I just removed the static master pointer completely, changed the constructor so that if Root == 0 then Root = new FGPropertyManager(), and in the destructor, just delete Root instead. Now everything works just fine! :-) So I need some input from you guys now -- I can't really see the real use for the "master" pointer at all, it's barely used by the FGFDMExec class, and it's also not declared as a public variable (neither is Root). The child FDM's (If I understand JSBSim correctly) should get the Root pointer passed to them anyway so they also don't need it. Now they actually don't - in FGFDMExec::ReadChild, the object is created without passing the Root pointer, for some reason, so right now, my fix has probably broken something somewhere. What are the child FDM's for? Best regards, Ola |