FGFDMExec class seems to break when placed in a C++ array or vector #999
-
Hello everyone! I'm working on a project where I want to run N number of aircraft flight dynamic models simultaneously, and write JSBSim property values about their position to each other on every iteration, so that the autopilot and systems can make react based on the positions of the other aircraft. However I'm running into issues with the FGFDMExec class in the C++ API. For some reason, once I place the class inside an array, the code breaks when I execute the RunIC() or Run() class methods. Here's a code sample of the issue distilled down to the relevant parts.
For some reason, an exception is thrown when attempting to call the instances Run() method once they are inside the vector. This also happens if I run RunIC() once the instance is inside the vector. However it has no problem accessing any other method such as GetAircraftPath(). This problem also occurs if I use arrays instead of vectors. I can avoid this problem by not using arrays / vectors. I can create a separate variable for each FGFDMExec class, and then run multiple cases simultaneously just fine (although this does not let me create N arbitrary aircraft models). So the issue isn't with defining multiple FGFDMExec classes. For some reason, it seems that the FGFDMExec class is breaking once placed in array. My C++ knowledge is quite limited so there may be something obvious staring me in the face. Any help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Take a look at - https://stackoverflow.com/questions/2275076/is-stdvector-copying-the-objects-with-a-push-back |
Beta Was this translation helpful? Give feedback.
Fixed it. After reading the link above I understand a little bit better about the distinctions between pointing reference, and copying. Pre-initializing the vector solved the issue.