Skip to content

Commit

Permalink
Don't crash on pipe errors, just log them
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirenliel committed Aug 22, 2021
1 parent 4370def commit af3aab8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/eiren/vr/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Main {

public static String VERSION = "0.0.15 Test 2";
public static String VERSION = "0.0.16";

public static VRServer vrServer;

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/eiren/vr/bridge/NamedPipeVRBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public boolean updateHMD() throws IOException {
commandBuilder.setLength(0);
} else {
commandBuilder.append(c);
if(commandBuilder.length() >= MAX_COMMAND_LENGTH)
throw new IOException("Command from the pipe is too long");
if(commandBuilder.length() >= MAX_COMMAND_LENGTH) {
LogManager.log.severe("[VRBridge] Command from the pipe is too long, flushing buffer");
commandBuilder.setLength(0);
}
}
}
if(bytesRead < buffArray.length)
Expand All @@ -144,6 +146,10 @@ public boolean updateHMD() throws IOException {

private void executeHMDInput() throws IOException {
String[] split = commandBuilder.toString().split(" ");
if(split.length < 7) {
LogManager.log.severe("[VRBridge] Short HMD data recieved: " + commandBuilder.toString());
return;
}
try {
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/io/eiren/vr/bridge/SteamVRPipeInputBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public boolean updatePipes() throws IOException {
commandBuilder.setLength(0);
} else {
commandBuilder.append(c);
if(commandBuilder.length() >= MAX_COMMAND_LENGTH)
throw new IOException("Command from the pipe is too long");
if(commandBuilder.length() >= MAX_COMMAND_LENGTH) {
LogManager.log.severe("[SteamVRPipeInputBridge] Command from the pipe is too long, flushing buffer");
commandBuilder.setLength(0);
}
}
}
if(bytesRead < buffArray.length)
Expand All @@ -99,8 +101,10 @@ private void executeInputCommand() throws IOException {
String[] command = commandBuilder.toString().split(" ");
switch(command[0]) {
case "ADD": // Add new tracker
if(command.length < 4)
throw new IOException("Error in ADD command. Command requires at least 4 arguments. Supplied: " + commandBuilder.toString());
if(command.length < 4) {
LogManager.log.severe("[SteamVRPipeInputBridge] Error in ADD command. Command requires at least 4 arguments. Supplied: " + commandBuilder.toString());
return;
}
SteamVRTracker internalTracker = new SteamVRTracker(Integer.parseInt(command[1]), StringUtils.join(command, " ", 3, command.length));
int roleId = Integer.parseInt(command[2]);
if(roleId >= 0 && roleId < SteamVRInputRoles.values.length) {
Expand All @@ -111,13 +115,17 @@ private void executeInputCommand() throws IOException {
synchronized(trackersInternal) {
oldTracker = trackersInternal.put(internalTracker.id, internalTracker);
}
if(oldTracker != null)
throw new IOException("New tracker added with the same id. Supplied: " + commandBuilder.toString());
if(oldTracker != null) {
LogManager.log.severe("[SteamVRPipeInputBridge] New tracker added with the same id. Supplied: " + commandBuilder.toString());
return;
}
newData.set(true);
break;
case "UPD": // Update tracker data
if(command.length < 9)
throw new IOException("Error in UPD command. Command requires at least 9 arguments. Supplied: " + commandBuilder.toString());
if(command.length < 9) {
LogManager.log.severe("[SteamVRPipeInputBridge] Error in UPD command. Command requires at least 9 arguments. Supplied: " + commandBuilder.toString());
return;
}
int id = Integer.parseInt(command[1]);
double x = Double.parseDouble(command[2]);
double y = Double.parseDouble(command[3]);
Expand All @@ -135,13 +143,17 @@ private void executeInputCommand() throws IOException {
}
break;
case "STA": // Update tracker status
if(command.length < 3)
throw new IOException("Error in STA command. Command requires at least 3 arguments. Supplied: " + commandBuilder.toString());
if(command.length < 3) {
LogManager.log.severe("[SteamVRPipeInputBridge] Error in STA command. Command requires at least 3 arguments. Supplied: " + commandBuilder.toString());
return;
}
id = Integer.parseInt(command[1]);
int status = Integer.parseInt(command[2]);
TrackerStatus st = TrackerStatus.getById(status);
if(st == null)
throw new IOException("Unrecognized status id. Supplied: " + commandBuilder.toString());
if(st == null) {
LogManager.log.severe("[SteamVRPipeInputBridge] Unrecognized status id. Supplied: " + commandBuilder.toString());
return;
}
internalTracker = trackersInternal.get(id);
if(internalTracker != null) {
internalTracker.setStatus(st);
Expand Down

0 comments on commit af3aab8

Please sign in to comment.