Go to Post Most importantly, get some sleep. - Libby K [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-01-2014, 20:21
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Calling LiveWindow::GetInstance() during static initialization causes program crash

I've been trying out a new way of organizing my team's code, which involves initializing subsystems during static initialization. Unfortunately, if I initialize a Talon statically in a namespace, the program crashes. Monitoring the output via netconsole gives this:

Quote:
* Loading FRC_UserProgram.out: FRC_UserProgram


[NT] NetworkTable::GetTable()...

[NT] Initializing...

[NT] NetworkTable::CheckInit()...

[NT] NetworkTable::Initialize()...



program

Exception current instruction address: 0x00000000

Machine Status Register: 0x0008b012

Condition Register: 0x24004282

Task: 0xb6ec60 "Main Application Thread"

0xb6ec60 (Main Application Thread): task 0xb6ec60 has had a failure and has been stopped.

0xb6ec60 (Main Application Thread): fatal kernel task-level exception!
That last message before the exception comes right before this function call in the NetworkTables code:

Code:
staticProvider = new NetworkTableProvider(*(staticNode = mode->CreateNode(ipAddress.c_str(), port, threadManager, streamFactory, streamDeleter, typeManager)));
Which is called because a NetworkTable::GetTable() call in LiveWindow::LiveWindow() called by LiveWindow::GetInstance() checks to see if NetworkTable::staticProvider is NULL, and if so, creates it. Moving the initialization to the RobotInit() function fixes the problem, and the messages related to setting NetworkTable::staticProvider are not displayed. So basically, my question is this: Where does NetworkTable::staticProvider get set, and is there a way around this, short of intializing in RobotInit?
Reply With Quote
  #2   Spotlight this post!  
Unread 13-01-2014, 20:31
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

This sounds similar to the following bug, although no details are given: http://firstforge.wpi.edu/sf/go/artf1653 or maybe this one: http://firstforge.wpi.edu/sf/go/artf1644

Last edited by Joe Ross : 13-01-2014 at 20:34.
Reply With Quote
  #3   Spotlight this post!  
Unread 13-01-2014, 22:57
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Yeah, it looks like those are the same issue. I wonder if there's any plan to address that in the near future.
Reply With Quote
  #4   Spotlight this post!  
Unread 16-01-2014, 01:40
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Quote:
Originally Posted by MaraschinoPanda View Post
Where does NetworkTable::staticProvider get set, and is there a way around this, short of intializing in RobotInit?
None of the initialization rules are documented as far as I can tell. If anyone comes across something that says what they are I would love to know too.
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2014, 19:11
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

There's an issue where statically initialized classes are not created in any specific order. So that means that variables, in particular, lists of the sensors and speed controllers might not have been initialized when the static classes are created.

The best solution is to try to not create WPILib objects statically and instead make them class members. Then you can initialize them from the heap using new or as class members. This makes sure that they don't get initialized before the underlying WPILib code starts up.

But we're looking at the problem now. May be an update.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #6   Spotlight this post!  
Unread 17-01-2014, 19:59
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Just curious, what variables are actually being initialized statically to cause this bug? I couldn't seem to track them down.
Reply With Quote
  #7   Spotlight this post!  
Unread 20-01-2014, 11:24
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 350
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Quote:
Originally Posted by BradAMiller View Post
There's an issue where statically initialized classes are not created in any specific order. So that means that variables, in particular, lists of the sensors and speed controllers might not have been initialized when the static classes are created.

The best solution is to try to not create WPILib objects statically and instead make them class members. Then you can initialize them from the heap using new or as class members. This makes sure that they don't get initialized before the underlying WPILib code starts up.

But we're looking at the problem now. May be an update.
I ran into this issue making a very simple robot program using the "SimpleTemplate". So it has a class (RobotDemo) derived from SimpleRobot that's initialized via START_ROBOT_CLASS(RobotDemo).

SimpleRobot's constructor invokes base class RobotBase constructor, which invokes DriverStation::GetInstance(), which ultimately leads to NetworkTables::Initialize() which crashes for the reasons described herein.

So unless I'm missing something obvious, the current C++ RobotBase is unusable, since it has to be statically initialized via START_ROBOT_CLASS.

I'd love to know if there's a work around for this; it seems like a pretty serious problem that's got me stopped in my tracks....
Reply With Quote
  #8   Spotlight this post!  
Unread 20-01-2014, 13:14
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 350
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Quote:
Originally Posted by slibert View Post
I ran into this issue making a very simple robot program using the "SimpleTemplate". So it has a class (RobotDemo) derived from SimpleRobot that's initialized via START_ROBOT_CLASS(RobotDemo).

SimpleRobot's constructor invokes base class RobotBase constructor, which invokes DriverStation::GetInstance(), which ultimately leads to NetworkTables::Initialize() which crashes for the reasons described herein.

So unless I'm missing something obvious, the current C++ RobotBase is unusable, since it has to be statically initialized via START_ROBOT_CLASS.

I'd love to know if there's a work around for this; it seems like a pretty serious problem that's got me stopped in my tracks....
FWIW, the issue seems to be that the virtual table for the static NetworkTableMode::Server object (an instance of NetworkTableServerMode class) is not yet initialized when NetworkTables::Initialize() is invoked; when NetworkTables::Initialize() attempts to use the NetworkTableServerMode object to invoke the virtual member function CreateNode(), the virtual table for the Server object hasn't yet been initialized because the NetworkTableServerMode constructor hasn't yet been invoked. So as Greg said, it's unordered static object construction that's causing it. However, it's happening within the WPILibrary itself (from within the RobotBase constructor), rather than in our robot code.
Reply With Quote
  #9   Spotlight this post!  
Unread 20-01-2014, 13:54
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 350
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: Calling LiveWindow::GetInstance() during static initialization causes program cra

Quote:
Originally Posted by slibert View Post
FWIW, the issue seems to be that the virtual table for the static NetworkTableMode::Server object (an instance of NetworkTableServerMode class) is not yet initialized when NetworkTables::Initialize() is invoked; when NetworkTables::Initialize() attempts to use the NetworkTableServerMode object to invoke the virtual member function CreateNode(), the virtual table for the Server object hasn't yet been initialized because the NetworkTableServerMode constructor hasn't yet been invoked. So as Greg said, it's unordered static object construction that's causing it. However, it's happening within the WPILibrary itself (from within the RobotBase constructor), rather than in our robot code.
Final Update: Looks like I goofed.

I believe this was happening because I was using a project created with last year's Sample Project creator in WindRiver, even though I'd updated to the latest 2014 release of the FRC C++ Update.

When I recreated the project (same process, but it was created after the 2014 update was installed into windriver), I'm not seeing this issue.

My apologies if I've wasted anyone's energy or time.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:01.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi