Log in

View Full Version : Relay AllocationException


EHaskins
13-02-2010, 02:47
When attempting to initialize relays on a additional Sidecar, connected to slot 6, I receive an AllocationException with a message to the effect of: "Channel X on slot Y has already been initalized."

Adding the code "Relay r = new Relay(6, 1);" to RobotInit() in an empty project reproduces this error.

Is there a solution to this?

MattD
13-02-2010, 03:25
It looks like you've found a bug in WPILibJ. I've looked at the source for the Relay class, and it appears that it only allocates a Resource object large enough track relay channels on the first DIO module.

Java version:
private static Resource relayChannels = new Resource(tDIO.kNumSystems * kRelayChannels);

This isn't enough, since a separate resource is allocated for Forward and Reverse.

C++ version:
Resource::CreateResourceObject(&relayChannels, tDIO::kNumSystems * kRelayChannels * 2);

Until it's fixed in an update, you could copy the Relay.java source code from ~/sunspotfrcsdk/lib/WPILibJ/src into your project and correct it by adding in the factor of 2.

If this fixes the issue a bug report should be submitted on FIRSTForge.

EHaskins
13-02-2010, 09:41
I'll try that today.

Thanks.

EHaskins
14-02-2010, 15:30
That fixed it. Works perfectly now.