[Bf-blender-cvs] [1e2253a8da7] vr_scene_inspection: Cleanup: Avoid macros, don't print source location for errors
Julian Eisel
noreply at git.blender.org
Tue Mar 10 16:44:41 CET 2020
Commit: 1e2253a8da7774b16f80456d88e59453d4ffb9f2
Author: Julian Eisel
Date: Mon Mar 9 18:58:20 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB1e2253a8da7774b16f80456d88e59453d4ffb9f2
Cleanup: Avoid macros, don't print source location for errors
===================================================================
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_XrContext.cpp
M intern/ghost/intern/GHOST_XrEvent.cpp
M intern/ghost/intern/GHOST_XrException.h
M intern/ghost/intern/GHOST_XrSession.cpp
M intern/ghost/intern/GHOST_Xr_intern.h
===================================================================
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 4be2c4dc774..79c9b129fad 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -659,9 +659,6 @@ typedef struct {
typedef struct {
const char *user_message;
- /** File path and line number the error was found at. */
- const char *source_location;
-
void *customdata;
} GHOST_XrError;
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index e1a6911e788..410837e9805 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -84,7 +84,9 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
{
initApiLayers();
initExtensions();
- XR_DEBUG_ONLY_CALL(this, printAvailableAPILayersAndExtensionsInfo());
+ if (isDebugMode()) {
+ printAvailableAPILayersAndExtensionsInfo();
+ }
m_gpu_binding_type = determineGraphicsBindingTypeToEnable(create_info);
@@ -92,7 +94,9 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
createOpenXRInstance();
storeInstanceProperties();
printInstanceInfo();
- XR_DEBUG_ONLY_CALL(this, initDebugMessenger());
+ if (isDebugMode()) {
+ initDebugMessenger();
+ }
}
void GHOST_XrContext::createOpenXRInstance()
@@ -109,7 +113,9 @@ void GHOST_XrContext::createOpenXRInstance()
create_info.enabledApiLayerNames = m_enabled_layers.data();
create_info.enabledExtensionCount = m_enabled_extensions.size();
create_info.enabledExtensionNames = m_enabled_extensions.data();
- XR_DEBUG_ONLY_CALL(this, printExtensionsAndAPILayersToEnable());
+ if (isDebugMode()) {
+ printExtensionsAndAPILayersToEnable();
+ }
CHECK_XR(xrCreateInstance(&create_info, &m_oxr->instance),
"Failed to connect to an OpenXR runtime.");
@@ -231,23 +237,17 @@ void GHOST_XrContext::initDebugMessenger()
void GHOST_XrContext::dispatchErrorMessage(const GHOST_XrException *exception) const
{
- std::ostringstream stream_err_location;
- std::string str_err_location;
GHOST_XrError error;
- stream_err_location << exception->m_file << ":" << exception->m_line;
- str_err_location = stream_err_location.str();
-
error.user_message = exception->m_msg;
- error.source_location = str_err_location.c_str();
error.customdata = s_error_handler_customdata;
- XR_DEBUG_ONLY_CALL(this,
- fprintf(stderr,
- "Error: \t%s\n\tOpenXR error value: %i\n\tSource: (%s)\n",
- error.user_message,
- exception->m_result,
- error.source_location));
+ if (isDebugMode()) {
+ fprintf(stderr,
+ "Error: \t%s\n\tOpenXR error value: %i\n",
+ error.user_message,
+ exception->m_result);
+ }
/* Potentially destroys GHOST_XrContext */
s_error_handler(&error);
@@ -359,7 +359,9 @@ void GHOST_XrContext::getAPILayersToEnable(std::vector<const char *> &r_ext_name
try_layers.clear();
- XR_DEBUG_ONLY_CALL(this, try_layers.push_back("XR_APILAYER_LUNARG_core_validation"));
+ if (isDebugMode()) {
+ try_layers.push_back("XR_APILAYER_LUNARG_core_validation");
+ }
r_ext_names.reserve(try_layers.size());
@@ -401,7 +403,9 @@ void GHOST_XrContext::getExtensionsToEnable(std::vector<const char *> &r_ext_nam
/* Try enabling debug extension. */
#ifndef WIN32
- XR_DEBUG_ONLY_CALL(this, try_ext.push_back(XR_EXT_DEBUG_UTILS_EXTENSION_NAME));
+ if (isDebugMode()) {
+ try_ext.push_back(XR_EXT_DEBUG_UTILS_EXTENSION_NAME);
+ }
#endif
r_ext_names.reserve(try_ext.size() + 1); /* + 1 for graphics binding extension. */
diff --git a/intern/ghost/intern/GHOST_XrEvent.cpp b/intern/ghost/intern/GHOST_XrEvent.cpp
index 25553508af0..dfee2e95f10 100644
--- a/intern/ghost/intern/GHOST_XrEvent.cpp
+++ b/intern/ghost/intern/GHOST_XrEvent.cpp
@@ -53,7 +53,9 @@ GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_contexthandle)
GHOST_XrContextDestroy(xr_contexthandle);
return GHOST_kSuccess;
default:
- XR_DEBUG_PRINTF(xr_context, "Unhandled event: %i\n", event->type);
+ if (xr_context->isDebugMode()) {
+ printf("Unhandled event: %i\n", event->type);
+ }
return GHOST_kFailure;
}
}
diff --git a/intern/ghost/intern/GHOST_XrException.h b/intern/ghost/intern/GHOST_XrException.h
index abcd57b6ce0..9f779961e4f 100644
--- a/intern/ghost/intern/GHOST_XrException.h
+++ b/intern/ghost/intern/GHOST_XrException.h
@@ -27,8 +27,8 @@ class GHOST_XrException : public std::exception {
friend class GHOST_XrContext;
public:
- GHOST_XrException(const char *msg, const char *file, int line, int result = 0)
- : std::exception(), m_msg(msg), m_file(file), m_line(line), m_result(result)
+ GHOST_XrException(const char *msg, int result = 0)
+ : std::exception(), m_msg(msg), m_result(result)
{
}
@@ -39,8 +39,6 @@ class GHOST_XrException : public std::exception {
private:
const char *m_msg;
- const char *m_file;
- const int m_line;
int m_result;
};
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index cab94a4774a..d96daeb7dd6 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -153,7 +153,7 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
assert(m_context->getInstance() != XR_NULL_HANDLE);
assert(m_oxr->session == XR_NULL_HANDLE);
if (m_context->getCustomFuncs().gpu_ctx_bind_fn == nullptr) {
- THROW_XR(
+ throw GHOST_XrException(
"Invalid API usage: No way to bind graphics context to the XR session. Call "
"GHOST_XrGraphicsContextBindFuncs() with valid parameters before starting the "
"session (through GHOST_XrSessionStart()).");
@@ -163,7 +163,7 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
bindGraphicsContext();
if (m_gpu_ctx == nullptr) {
- THROW_XR(
+ throw GHOST_XrException(
"Invalid API usage: No graphics context returned through the callback set with "
"GHOST_XrGraphicsContextBindFuncs(). This is required for session starting (through "
"GHOST_XrSessionStart()).");
@@ -176,7 +176,7 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
std::ostringstream strstream;
strstream << "Available graphics context version does not meet the following requirements: "
<< requirement_str;
- THROW_XR(strstream.str().c_str());
+ throw GHOST_XrException(strstream.str().c_str());
}
m_gpu_binding->initFromGhostContext(m_gpu_ctx);
@@ -279,7 +279,8 @@ static unique_oxr_ptr<XrSwapchain> swapchain_create(const XrSession session,
assert(swapchain_formats.size() == format_count);
if (!gpu_binding->chooseSwapchainFormat(swapchain_formats, &chosen_format)) {
- THROW_XR("Error: No format matching OpenXR runtime supported swapchain formats found.");
+ throw GHOST_XrException(
+ "Error: No format matching OpenXR runtime supported swapchain formats found.");
}
create_info.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT |
diff --git a/intern/ghost/intern/GHOST_Xr_intern.h b/intern/ghost/intern/GHOST_Xr_intern.h
index 2a0ab86b181..a3a86096015 100644
--- a/intern/ghost/intern/GHOST_Xr_intern.h
+++ b/intern/ghost/intern/GHOST_Xr_intern.h
@@ -30,7 +30,7 @@
{ \
XrResult _res = call; \
if (XR_FAILED(_res)) { \
- throw GHOST_XrException(error_msg, __FILE__, __LINE__, _res); \
+ throw GHOST_XrException(error_msg, _res); \
} \
} \
(void)0
@@ -43,27 +43,6 @@
} \
(void)0
-#define THROW_XR(error_msg) throw GHOST_XrException(error_msg, __FILE__, __LINE__);
-
-#define XR_DEBUG_ONLY_BEGIN(ctx) \
- if ((ctx)->isDebugMode()) { \
- (void)0
-#define XR_DEBUG_ONLY_END \
- } \
- (void)0
-
-#define XR_DEBUG_PRINTF(ctx, ...) \
- if ((ctx)->isDebugMode()) { \
- printf(__VA_ARGS__); \
- } \
- (void)0
-
-#define XR_DEBUG_ONLY_CALL(ctx, call) \
- if ((ctx)->isDebugMode()) { \
- call; \
- } \
- (void)0
-
/**
* Helper for RAII usage of OpenXR handles (defined with XR_DEFINE_HANDLE). This is based on
* `std::unique_ptr`, to give similar behavior and usage (e.g. functions like #get() and #release()
More information about the Bf-blender-cvs
mailing list