mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-05 16:22:32 -08:00
Better tracker id with no possible null pointer exception
This commit is contained in:
1 parent
f72045438e
commit
18386d57d6
1 file changed
+14
-9
@@ -306,18 +306,23 @@ public class VRServer extends Thread {
|
||||
}
|
||||
|
||||
public Tracker getTrackerById(TrackerIdT id) {
|
||||
|
||||
for (Tracker tracker : trackers) {
|
||||
if (tracker.getTrackerNum() != id.getTrackerNum())
|
||||
if (tracker.getTrackerNum() != id.getTrackerNum()) {
|
||||
continue;
|
||||
// A tracker id is a combination of two data, the device id (optional) and the tracker num
|
||||
// tracker.getDevice() can be null for synthetic trackers
|
||||
// if device id is null but the tracker id has a device id, the tracker should be skipped
|
||||
// On the other hand if the tracker has a device id but the TrackerId does not have one we should also skip
|
||||
if (tracker.getDevice() == null ^ id.getDeviceId() == null)
|
||||
}
|
||||
|
||||
// Handle synthetic devices
|
||||
if (id.getDeviceId() == null) {
|
||||
if (tracker.getDevice() == null)
|
||||
return tracker;
|
||||
continue;
|
||||
if (tracker.getDevice().getId() != id.getDeviceId().getId())
|
||||
continue;
|
||||
return tracker;
|
||||
}
|
||||
// We now know that the argument is not a synthetic tracker
|
||||
|
||||
if (tracker.getDevice() != null && id.getDeviceId().getId() == tracker.getDevice().getId()) {
|
||||
return tracker;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user