View Single Post
  #2   Spotlight this post!  
Unread 17-01-2016, 15:54
calcmogul's Avatar
calcmogul calcmogul is offline
WPILib Developer
AKA: Tyler Veness
FRC #3512 (Spartatroniks)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Santa Maria, CA
Posts: 52
calcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nice
Re: Robotbuilder c++ code dies in Test Mode

Quote:
Originally Posted by Joe Ross View Post
Here's code that works:
Code:
lw->AddActuator("Subsystem 1", "Speed Controller 1",  std::static_pointer_cast<Talon>(subsystem1SpeedController1));
I'm not a C++ guru, so I'm not sure if that's the right method to cast the shared_pointer from a SpeedController to Talon or other class that implements a SpeedController.
I think std::static_pointer_cast will work here. The type is definitely a Talon, so std::dynamic_pointer_cast isn't necessary. Note that the pointer passed in can't be that of a stack allocated object or a double-free would occur later.

Quote:
Originally Posted by Joe Ross View Post
Here's the code that causes the crash:

Code:
lw->AddActuator("Subsystem 1", "Speed Controller 1",  (Talon&)subsystem1SpeedController1);
Is subsystem1SpeedController1 an object or pointer to an object? If the suggested code is correct, then subsystem1SpeedController1 is a pointer and casting to Talon& seems strange to me anyway.
Reply With Quote