From cd4c5c75513d99ef4d5d68beb2f294a168abee7d Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 14:04:04 -0500 Subject: [PATCH 1/9] change int to std::uint8_t. Add some logging to check value of eye index. --- OsvrRenderingPlugin.cpp | 46 ++++++++++++++++++++++++++++++++++------- OsvrRenderingPlugin.h | 9 ++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 3bd7d21..b427cd2 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -677,17 +677,49 @@ void UNITY_INTERFACE_API SetIPD(double ipdMeters) { } osvr::renderkit::OSVR_ViewportDescription UNITY_INTERFACE_API -GetViewport(int eye) { - return s_renderInfo[eye].viewport; +GetViewport(std::uint8_t eye) { + osvr::renderkit::OSVR_ViewportDescription viewportDescription; + if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) + { + viewportDescription = s_renderInfo[eye].viewport; + } + else + { + std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetViewport, eye = " + eye; + DebugLog(errorLog.c_str()); + } + return viewportDescription; } osvr::renderkit::OSVR_ProjectionMatrix UNITY_INTERFACE_API -GetProjectionMatrix(int eye) { - return s_renderInfo[eye].projection; +GetProjectionMatrix(std::uint8_t eye) { + osvr::renderkit::OSVR_ProjectionMatrix pm; + if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) + { + pm = s_renderInfo[eye].projection; + } + else + { + std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetProjectionMatrix, eye = " + eye; + DebugLog(errorLog.c_str()); + } + return pm; } -OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye) { - return s_renderInfo[eye].pose; +OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) { + OSVR_Pose3 pose; + osvrPose3SetIdentity(&pose); + if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) + { + std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + eye; + pose = s_renderInfo[eye].pose; + } + else + { + std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetEyePose, eye = " + eye; + DebugLog(errorLog.c_str()); + } + return pose; } // -------------------------------------------------------------------------- @@ -703,7 +735,7 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye) { // to set up needed texture pointers only at initialization time. // For more reference, see: // http://docs.unity3d.com/ScriptReference/Texture.GetNativeTexturePtr.html -int UNITY_INTERFACE_API SetColorBufferFromUnity(void *texturePtr, int eye) { +int UNITY_INTERFACE_API SetColorBufferFromUnity(void *texturePtr, std::uint8_t eye) { if (!s_deviceType) { return OSVR_RETURN_FAILURE; } diff --git a/OsvrRenderingPlugin.h b/OsvrRenderingPlugin.h index 25e9687..57d79c2 100644 --- a/OsvrRenderingPlugin.h +++ b/OsvrRenderingPlugin.h @@ -28,6 +28,7 @@ Sensics, Inc. #include #include #include +#include typedef void(UNITY_INTERFACE_API *DebugFnPtr)(const char *); @@ -45,18 +46,18 @@ ConstructRenderBuffers(); UNITY_INTERFACE_EXPORT OSVR_ReturnCode UNITY_INTERFACE_API CreateRenderManagerFromUnity(OSVR_ClientContext context); -UNITY_INTERFACE_EXPORT OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye); +UNITY_INTERFACE_EXPORT OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye); UNITY_INTERFACE_EXPORT osvr::renderkit::OSVR_ProjectionMatrix UNITY_INTERFACE_API - GetProjectionMatrix(int eye); + GetProjectionMatrix(std::uint8_t eye); UNITY_INTERFACE_EXPORT UnityRenderingEvent UNITY_INTERFACE_API GetRenderEventFunc(); UNITY_INTERFACE_EXPORT osvr::renderkit::OSVR_ViewportDescription UNITY_INTERFACE_API - GetViewport(int eye); + GetViewport(std::uint8_t eye); UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API LinkDebug(DebugFnPtr d); @@ -64,7 +65,7 @@ UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API OnRenderEvent(int eventID); /// @todo should return OSVR_ReturnCode UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API -SetColorBufferFromUnity(void *texturePtr, int eye); +SetColorBufferFromUnity(void *texturePtr, std::uint8_t eye); UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetFarClipDistance(double distance); From b9ad253c7dafdd4b740537d089af71494d4c95d9 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 14:04:39 -0500 Subject: [PATCH 2/9] enable logging. --- OsvrRenderingPlugin.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index b427cd2..56b82e0 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -21,8 +21,8 @@ Sensics, Inc. // limitations under the License. /// Both of these need to be enabled to force-enable logging to files. -#undef ENABLE_LOGGING -#undef ENABLE_LOGFILE +#define ENABLE_LOGGING 1 +#define ENABLE_LOGFILE 1 // Internal includes #include "OsvrRenderingPlugin.h" @@ -634,7 +634,7 @@ inline void CleanupBufferD3D11(osvr::renderkit::RenderBuffer &rb) { OSVR_ReturnCode UNITY_INTERFACE_API ConstructRenderBuffers() { if (!s_deviceType) { - DebugLog("Device type not supported."); + DebugLog("[OSVR Rendering Plugin] Device type not supported."); return OSVR_RETURN_FAILURE; } UpdateRenderInfo(); From 0fe7801af418ac09e044cae924c87e6abf3b4f9f Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 14:39:18 -0500 Subject: [PATCH 3/9] updated logging --- OsvrRenderingPlugin.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 56b82e0..89df485 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -711,12 +711,11 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) { osvrPose3SetIdentity(&pose); if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) { - std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + eye; pose = s_renderInfo[eye].pose; } else { - std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetEyePose, eye = " + eye; + std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pose; From ee115677667b7c13a93931ad607c7a1fcb2caf63 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 15:36:56 -0500 Subject: [PATCH 4/9] added logging --- OsvrRenderingPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 89df485..1a66783 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -685,7 +685,7 @@ GetViewport(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetViewport, eye = " + eye; + std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return viewportDescription; @@ -700,7 +700,7 @@ GetProjectionMatrix(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] Index out of range in GetProjectionMatrix, eye = " + eye; + std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pm; From 3b2ef3050d747522338e33966de3b0f982be54a4 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 15:49:54 -0500 Subject: [PATCH 5/9] updated logging --- OsvrRenderingPlugin.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 1a66783..2be7afd 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -685,7 +685,7 @@ GetViewport(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); + std::string errorLog = "[OSVR Rendering Plugin] error in GetViewport, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return viewportDescription; @@ -700,7 +700,7 @@ GetProjectionMatrix(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); + std::string errorLog = "[OSVR Rendering Plugin] error in GetProjectionMatrix, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pm; @@ -715,7 +715,7 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] working, eye = " + std::to_string(int(eye)); + std::string errorLog = "[OSVR Rendering Plugin] error in GetEyePose, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pose; From bd0edc0589cbcd9254895de277a0c04737ce9463 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 16:24:36 -0500 Subject: [PATCH 6/9] more logging --- OsvrRenderingPlugin.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 2be7afd..a39247f 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -687,6 +687,8 @@ GetViewport(std::uint8_t eye) { { std::string errorLog = "[OSVR Rendering Plugin] error in GetViewport, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); + errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + DebugLog(errorLog.c_str()); } return viewportDescription; } @@ -702,6 +704,8 @@ GetProjectionMatrix(std::uint8_t eye) { { std::string errorLog = "[OSVR Rendering Plugin] error in GetProjectionMatrix, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); + errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + DebugLog(errorLog.c_str()); } return pm; } @@ -717,6 +721,8 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) { { std::string errorLog = "[OSVR Rendering Plugin] error in GetEyePose, eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); + errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + DebugLog(errorLog.c_str()); } return pose; } From af7daac3ccf29aecf224f9b35f15e190bdd13745 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Thu, 8 Dec 2016 17:05:33 -0500 Subject: [PATCH 7/9] return default HDK2 viewport when renderInfo size=0 bug occurs --- OsvrRenderingPlugin.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index a39247f..a61e48e 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -682,6 +682,14 @@ GetViewport(std::uint8_t eye) { if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) { viewportDescription = s_renderInfo[eye].viewport; + /*std::string d0 = "[OSVR Rendering Plugin] viewportDescription, eye = " + std::to_string(int(eye)); + std::string d1 = "left = " + std::to_string(int(s_renderInfo[eye].viewport.left)); + std::string d2 = "lower = " + std::to_string(int(s_renderInfo[eye].viewport.lower)); + std::string d3 = "width = " + std::to_string(int(s_renderInfo[eye].viewport.width)); + std::string d4 = "height = " + std::to_string(int(s_renderInfo[eye].viewport.height)); + std::string d5 = d0 + "\n" + d1 + "\n" + d2 + "\n" + d3 + "\n" + d4 + "\n"; + DebugLog(d5.c_str());*/ + } else { @@ -689,6 +697,10 @@ GetViewport(std::uint8_t eye) { DebugLog(errorLog.c_str()); errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); DebugLog(errorLog.c_str()); + viewportDescription.left = 0; + viewportDescription.lower = 0; + viewportDescription.width = 1080; + viewportDescription.height = 1200; } return viewportDescription; } From dad1c167bcd41c7774bc5cbac8fc377732e0ab59 Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Mon, 12 Dec 2016 13:40:44 -0500 Subject: [PATCH 8/9] cache non-zero viewport values for width and height, and return them instead of a zeroed viewport when that bug appears. --- OsvrRenderingPlugin.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index a61e48e..535da94 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -92,6 +92,9 @@ static double s_nearClipDistance = 0.1; static double s_farClipDistance = 1000.0; /// @todo is this redundant? (given renderParams) static double s_ipd = 0.063; +//cached viewport values +static std::uint32_t viewportWidth = 0; +static std::uint32_t viewportHeight = 0; #if defined(ENABLE_LOGGING) && defined(ENABLE_LOGFILE) static std::ofstream s_debugLogFile; @@ -682,25 +685,27 @@ GetViewport(std::uint8_t eye) { if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1) { viewportDescription = s_renderInfo[eye].viewport; - /*std::string d0 = "[OSVR Rendering Plugin] viewportDescription, eye = " + std::to_string(int(eye)); - std::string d1 = "left = " + std::to_string(int(s_renderInfo[eye].viewport.left)); - std::string d2 = "lower = " + std::to_string(int(s_renderInfo[eye].viewport.lower)); - std::string d3 = "width = " + std::to_string(int(s_renderInfo[eye].viewport.width)); - std::string d4 = "height = " + std::to_string(int(s_renderInfo[eye].viewport.height)); - std::string d5 = d0 + "\n" + d1 + "\n" + d2 + "\n" + d3 + "\n" + d4 + "\n"; - DebugLog(d5.c_str());*/ + //cache the viewport width and height + //patches issue where sometimes empty viewport is returned + //@todo fix the real cause of why this method bugs out occasionally on some machines, more often on others + if (viewportWidth == 0 && s_renderInfo[eye].viewport.width != 0) + { + viewportWidth = s_renderInfo[eye].viewport.width; + } + if (viewportHeight == 0 && s_renderInfo[eye].viewport.height != 0) + { + viewportHeight = s_renderInfo[eye].viewport.height; + } } else { - std::string errorLog = "[OSVR Rendering Plugin] error in GetViewport, eye = " + std::to_string(int(eye)); - DebugLog(errorLog.c_str()); - errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + std::string errorLog = "[OSVR Rendering Plugin] Error in GetViewport, returning cached values. Eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); viewportDescription.left = 0; viewportDescription.lower = 0; - viewportDescription.width = 1080; - viewportDescription.height = 1200; + viewportDescription.width = viewportWidth; + viewportDescription.height = viewportHeight; } return viewportDescription; } From 629403503ae5fd2e0f43ef86f70127816f2bd1bc Mon Sep 17 00:00:00 2001 From: Greg Aring Date: Mon, 12 Dec 2016 13:45:59 -0500 Subject: [PATCH 9/9] Disable logging and added comments. --- OsvrRenderingPlugin.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/OsvrRenderingPlugin.cpp b/OsvrRenderingPlugin.cpp index 535da94..1904406 100644 --- a/OsvrRenderingPlugin.cpp +++ b/OsvrRenderingPlugin.cpp @@ -21,8 +21,8 @@ Sensics, Inc. // limitations under the License. /// Both of these need to be enabled to force-enable logging to files. -#define ENABLE_LOGGING 1 -#define ENABLE_LOGFILE 1 +#undef ENABLE_LOGGING +#undef ENABLE_LOGFILE // Internal includes #include "OsvrRenderingPlugin.h" @@ -700,6 +700,7 @@ GetViewport(std::uint8_t eye) { } else { + //we shouldn't be here unless we hit a bug, in which case, we avoid error by returning cached viewport values std::string errorLog = "[OSVR Rendering Plugin] Error in GetViewport, returning cached values. Eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); viewportDescription.left = 0; @@ -719,9 +720,7 @@ GetProjectionMatrix(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] error in GetProjectionMatrix, eye = " + std::to_string(int(eye)); - DebugLog(errorLog.c_str()); - errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + std::string errorLog = "[OSVR Rendering Plugin] Error in GetProjectionMatrix, returning default values. Eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pm; @@ -736,9 +735,7 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) { } else { - std::string errorLog = "[OSVR Rendering Plugin] error in GetEyePose, eye = " + std::to_string(int(eye)); - DebugLog(errorLog.c_str()); - errorLog = "[OSVR Rendering Plugin] renderInfo array size is = " + std::to_string(int(s_renderInfo.size())); + std::string errorLog = "[OSVR Rendering Plugin] Error in GetEyePose, returning default values. Eye = " + std::to_string(int(eye)); DebugLog(errorLog.c_str()); } return pose;