I am (having previously upgraded it to OpenVR
http://forum.lwjgl.org/index.php?topic=7198.0) now planning on upgrading JMonkeyengine to OpenXR; we've got a fair way (The XR session boots and displays something somewhat sensible to the headset) but at the action set phase I'm getting an error I don't understand.
I've been following the example code at
https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#_action_overview and I'm getting error code -1. Which I believe is XR_ERROR_VALIDATION_FAILURE, The function usage was invalid in some way. This happens when I call xrSuggestInteractionProfileBindings.
The Khronis example uses a XrActionSuggestedBinding but I'm using a XrActionSuggestedBinding.Buffer, but that seems to be what the LWJGL XrInteractionProfileSuggestedBinding wants me to do
This is the suggest actions code I'm running. Is there anything obvious I'm doing wrong?
public void registerActions(){
XrActionSetCreateInfo actionSetCreate = XrActionSetCreateInfo.create();
actionSetCreate.actionSetName(stringToByte("test"));
actionSetCreate.localizedActionSetName(stringToByte("testTranslation"));
actionSetCreate.priority(0);
PointerBuffer actionSetPointer = BufferUtils.createPointerBuffer(1);
withResponseCodeLogging("Create action set", XR10.xrCreateActionSet(xrInstance, actionSetCreate, actionSetPointer));
actionSetCreate.close();
XrActionSet actionSet = new XrActionSet(actionSetPointer.get(), xrInstance);
activeActionSet = actionSet;
XrActionCreateInfo xrActionCreateInfo = XrActionCreateInfo.create();
xrActionCreateInfo.actionName(stringToByte("teleport"));
xrActionCreateInfo.actionType(ActionType.BOOLEAN.getOpenXrOption());
xrActionCreateInfo.localizedActionName(stringToByte("teleportTranslated"));
PointerBuffer actionPointer = BufferUtils.createPointerBuffer(1);
withResponseCodeLogging("xrStringToPath", XR10.xrCreateAction(actionSet, xrActionCreateInfo, actionPointer));
XrAction action = new XrAction(actionPointer.get(), actionSet);
teleportAction = action;
xrActionCreateInfo.close();
LongBuffer oculusProfilePath = BufferUtils.createLongBuffer(1);
withResponseCodeLogging("xrStringToPath", XR10.xrStringToPath(xrInstance, "/interaction_profiles/oculus/touch_controller", oculusProfilePath));
//XrcAtionSuggestedBinding suggestedBinding = XrActionSuggestedBinding.create();
LongBuffer xClickPathBuffer = BufferUtils.createLongBuffer(1);
withResponseCodeLogging("xrStringToPath",XR10.xrStringToPath(xrInstance,"/user/hand/left/input/x/click", xClickPathBuffer));
XrActionSuggestedBinding.Buffer suggestedBindingsBuffer = new XrActionSuggestedBinding.Buffer(BufferUtils.createByteBuffer(XrActionSuggestedBinding.SIZEOF));
suggestedBindingsBuffer.action(action);
suggestedBindingsBuffer.binding(xClickPathBuffer.get());
XrInteractionProfileSuggestedBinding xrInteractionProfileSuggestedBinding = XrInteractionProfileSuggestedBinding.create();
xrInteractionProfileSuggestedBinding.suggestedBindings(suggestedBindingsBuffer);
xrInteractionProfileSuggestedBinding.interactionProfile(oculusProfilePath.get());
//the below is the line returning the error code
withResponseCodeLogging("xrSuggestInteractionProfileBindings", XR10.xrSuggestInteractionProfileBindings(xrInstance, xrInteractionProfileSuggestedBinding));
actionSetPointer.rewind();
XrSessionActionSetsAttachInfo actionSetsAttachInfo = XrSessionActionSetsAttachInfo.create();
actionSetsAttachInfo.actionSets(actionSetPointer);
withResponseCodeLogging("xrAttachSessionActionSets", XR10.xrAttachSessionActionSets(xrSession, actionSetsAttachInfo));
}
private static ByteBuffer stringToByte(String str){
byte[] strBytes = str.getBytes(StandardCharsets.UTF_8);
byte[] nullTerminatedBytes = new byte[strBytes.length + 1];
System.arraycopy(strBytes, 0, nullTerminatedBytes, 0, strBytes.length);
nullTerminatedBytes[nullTerminatedBytes.length - 1] = 0; // add null terminator
ByteBuffer buffer = BufferUtils.createByteBuffer(nullTerminatedBytes.length);
buffer.put(nullTerminatedBytes);
buffer.rewind();
return buffer;
}
private static void withResponseCodeLogging(String eventText, int errorCode){
//error code 0 is ultra common and means all is well. Don't flood the logs with it
if (errorCode != 0){
CallResponseCode fullErrorDetails = CallResponseCode.getResponseCode(errorCode);
if (fullErrorDetails.isAnErrorCondition()){
logger.warning(fullErrorDetails.getFormattedErrorMessage() + " Occurred during " + eventText);
}else{
if (logger.isLoggable(Level.FINE)){
logger.info(fullErrorDetails.getFormattedErrorMessage() + " Occurred during " + eventText);
}
}
}
}