ReconstructMe SDK  1.1.739-75658
Real-time 3D reconstruction engine
 All Classes Files Functions Typedefs Enumerations Enumerator Groups Pages
example_reconstructmesdk_error_handling.cpp

Content

This examples shows how correct error handling is done for the one minute example.

Each method in ReconstructMe SDK returns an error code based on reme_error_t. This can be used to determine the outcome of the last invocation. In addition, methods such as reme_context_get_last_error, reme_context_get_first_error, reme_context_get_error_count, reme_context_pop_last_error and reme_context_pop_first_error provide addition error information.

Besides polling for error messages, you can register a callback function for logging messages.

Boost is only used to generate examples and is not necessary for working with this SDK.

#include <boost/test/unit_test.hpp>
#include <stdio.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
// A simple macro that checks for any errors and exits if a method invocation failed.
#define OK(s) \
if (s != REME_ERROR_SUCCESS) { \
const char *msg; \
int length; \
reme_context_get_last_error(c, &msg, &length); \
printf("Last error: %s", msg); \
reme_context_destroy(&c); \
exit(-1); \
} \
BOOST_AUTO_TEST_CASE(error_handling_per_method)
{
// Create a new context
// Compile for OpenCL device using defaults
// Create a new volume
OK(reme_volume_create(c, &v));
// ...
}
// Logging callback
void on_error(reme_log_severity_t sev, const char *msg, void *user_data)
{
switch (sev) {
{
printf("INFO: %s\n", msg);
break;
}
{
printf("WARNING: %s\n", msg);
break;
}
{
printf("ERROR: %s\n", msg);
break;
}
}
}
BOOST_AUTO_TEST_CASE(error_handling_logging)
{
// Create a new context
// Compile for OpenCL device using defaults
// ...
}
BOOST_AUTO_TEST_CASE(error_handling_critical_point)
{
// Create a new context
// Compile for OpenCL device using defaults
// ...
// Perform error checking at a critical point
int nerrors = 0;
for (int i = 0; i < nerrors; ++i) {
const char *msg;
int length;
reme_context_get_first_error(c, &msg, &length);
printf("%i : %s", msg);
}
// ...
}
BOOST_AUTO_TEST_SUITE_END()