wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.07k stars 614 forks source link

Statically initialized motor controllers throw an exception in C++ #4654

Closed CoryNessCTR closed 1 year ago

CoryNessCTR commented 1 year ago

Describe the bug Statically initializing a motor controller in C++ throws an exception "NIFPGA: Resource not initialized: GetFPGATime"

To Reproduce

  1. Create new C++ project
  2. Add following lines to Robot.cpp file:
    #include "frc/motorcontrol/Victor.h"
    frc::Victor v{5};

Expected behavior Robot program does not crash

Starlight220 commented 1 year ago

How was this not caught until now? Was it because everything was inside the Robot instance, which got constructed later?

ThadHouse commented 1 year ago

It’s C++ exclusive, it’s a race condition in some cases, and if other objects are initialized before the motor controllers, it will bypass the issue. And also we generally tell teams to avoid initializing statically.