-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Playing well with REPLs #1248
Comments
Due to the design of JSBSim, this task is trivial in most cases and can be made by a newcomer to JSBSim so I'm flagging this issue as a good first issue. |
Can I work on this? |
@XueSongTap, yes sure ! Just make sure to avoid submitting a huge PR with all the classes migrated to smart pointers at once. I'd rather suggest to start with a PR that just contains the changes for 1 or 2 classes and start the discussion from there. I don't know how familiar you are with JSBSim code but FYI JSBSim is designed to allocate all its memory during initialization which is done in 2 steps:
While running the simulation loop, JSBSim does not allocate nor release any memory. All the memory is released when the object |
That's a great idea @bcoconni - I also envision interesting use cases in Julia within Jupyter notebooks. |
I'd like to contribute to this issue by starting with migrating a couple of components to use smart pointers. Based on the repository structure and the recommendations in this thread, I plan to work on: models/flight_control/FGGain.cpp/FGGain.h Since this would be my first contribution to JSBSim, I'd appreciate any guidance or feedback. Could someone from the team confirm if these would be appropriate components to begin with? Thank you! |
I agree In jsbsim/src/models/flight_control/FGGain.h Lines 225 to 227 in e1ea4e8
And Line 72 in e1ea4e8
We might consider replacing the pointers using
Sure, I suggest you submit a PR with your proposal and we'll discuss your code from there. |
Some further thoughts about exceptions in JSBSim. I have this intuition that we should only throw exceptions when reading the XML files i.e. when calling the method But what about exceptions thrown during the simulation loop, such as the one below ? jsbsim/src/models/FGPropagate.cpp Lines 360 to 363 in e1ea4e8
Here the simulation loop will abort and leave JSBSim in an unpredictable state. Hopefully, the caller has an exception handler or it will be terminated by the OS. And even so, assuming the user will fix the property simulation/integrator/position/translational (or whatever property was improperly set), I am very skeptical that the simulation could be resumed.
For the particular case of this exception, I think that the error (setting the property to an illegal value) should be intercepted earlier i.e. at the very moment the property is modified, when an error message could be issued and the property left to its current legal value which would allow the simulation to continue. So we should be able to avoid throwing an exception in this case. Generally speaking, the idea is to use exceptions only during loading and avoid using them otherwise. I am not sure this policy is reasonable or even applicable to JSBSim but it makes sense to me. Thoughts ? |
That makes sense to keep exceptions for XML loading. Expanding on your idea. I noticed logging is configurable to different levels. So what if exceptions are made configurable to different options as well? And maybe having either a delegate, a function, variable, or a class, etc - basically some way that can universally be handled by the REPLs as a way to gracefully handle JSBSim errors/exceptions. For example if someone is running a standalone instance of JSBSim, it defaults to a basic level of exceptions, throwing the exceptions where it makes sense to. And then when JSBSim is used with REPLs or attached/embedded/etc with other programs, those users can select their desired level of exception. So that they can turn off JSBSim exceptions completely, and in place off JSBSim exceptions, then a delegate or some other means is called, so the REPLs/other programs can see there is an JSBSim error/exception and halt their simulation gracefully without crashing everything. |
Maybe I'm misunderstanding your point but we are already doing that, at least for some methods of the Python classes: C++ exceptions are converted to Python's. jsbsim/python/ExceptionManagement.h Lines 33 to 57 in e1ea4e8
Well everything is possible, for that we could replace the keyword |
JSBSim has traditionally been employed within monolithic applications (such as FlightGear), where any JSBSim error generally resulted in the termination of the entire program. This assumption has simplified error handling within JSBSim itself: errors were considered unrecoverable since the calling application was expected to terminate when they occurred.
These days are gone now that we are providing a Python module and a Matlab S-function. This has opened up new possibilities for using JSBSim in interactive Read-Eval-Print-Loop (REPL) environments. This shift necessitates a reassessment and upgrade of our error handling and object state management strategies.
Specifically, this issue aims to discuss the following key requirements for robust JSBSim usage within REPLs (including, but not limited to, Python and Matlab):
FGFDMExec
. This implies the need for mechanisms to:FGFDMExec::Load
again after a previous failure.FGFDMExec::Run
ifFGFDMExec::Load
has failed.To address these requirements, the following work areas should be addressed:
FGSwitch
#1230 and Memory leak fix and general improvements ofFGDistributor
#1245 addressed memory leaks that occurred during error conditions, which was previously not a concern since the operating system would automatically reclaim all reserved memory upon program termination.new
anddelete
by smart pointers (i.e.unique_ptr
andshared_ptr
).LogLevel
) to each error message.This issue serves as a starting point for discussing the necessary modifications and best practices to ensure that JSBSim can be used effectively and reliably in interactive environments. Future pull requests that contribute to this objective should reference this issue, to maintain a clear connection to the requirements and goals outlined here.
The text was updated successfully, but these errors were encountered: