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
Segfault if scheduled command falls out of scope #5
Comments
|
With the following change this does not segfault: class TinyBot(CommandBasedRobot):
def robotInit(self):
self.cmd = TestCommand()
self.cmd.start()Whilst segfaulting is not great... is there a particular reason why you're not holding a reference to the command instance you create? |
|
Ooh, that's nasty. We need to find anywhere in the code that Scheduler::GetInstance() is called and make sure we keep references around.. |
|
I've added some notes about this particular situation at https://robotpy.readthedocs.io/en/stable/2020_notes.html#my-code-segfaulted-and-there-s-no-python-stack-trace ... we can definitely fix it, but unless someone else does it, I won't get to it until later in the weekend, as I'd like to focus on getting the new trajectory stuff out. |
|
From the Chief Delphi poll, it seems most teams aren't having trouble with this, but needing to keep a reference to every command in a command group is proving frustrating. Can you point me to what I would need to do/understand to add the "keepalive" behavior? I looked at the commit for issue #1, but I couldn't find a good explanation online for the syntax of "keepalive" as used in the yml files. |
|
@restouffer the best reference for what keepalive does would be https://pybind11.readthedocs.io/en/stable/advanced/functions.html#keep-alive. I'll add a reference to that from robotpy-build's internal "docs". |
|
The challenge isn't actually keepalive in the normal send -- that's fairly straightforward. The problem here is that the command internally passes itself to the scheduler, and pybind11 isn't aware of that reference being passed -- so we need some callback that lets us know that the scheduler is taking a reference to something, and a callback when it's released. This is similar to the SmartDashboard.putData problem. Internally, the command is notified that it was removed from the scheduler (https://github.com/wpilibsuite/allwpilib/blob/29c82527a5a16126abe3e5dfb4e18ca432c29437/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp#L224), but that callback is private. A dumb workaround is to make every command nodelete -- so they would never die. However, I have to imagine such a memory leak would be a very bad idea, particularly for the way that you're using it. Another alternative is copy all of the source code for the command framework here, and change everything to use shared_ptr -- as I don't think wpilib would accept such a change, certainly not until next season. Then the reference counting would be pretty much automatic. Another alternative is go back to a pure python implementation, but my understanding was that some teams ran into performance problems? |
|
If I'm understanding correctly, the real issue is calling |
|
Yes, that is the issue. |
|
Please give 2020.2.2.2 a try, it should address this issue. Sorry for the delay. |
|
That works. Thanks! |
FRC2539 commentedJan 30, 2020
Consider the following program:
When run with
python3 robot.py sim, it results in the following crash:Commenting out the
cmd.start()line allows the simulator to start.The text was updated successfully, but these errors were encountered: