Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/libprojectM/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ auto Logging::HasCallback() -> bool
}

void Logging::Log(const std::string& message, LogLevel severity)
{
Log(message.c_str(), severity);
}

void Logging::Log(const char* message, LogLevel severity)
{
auto callback = GetLoggingCallback();

if (callback.callbackFunction == nullptr)
if (callback.callbackFunction == nullptr || message == nullptr)
{
return;
}

callback.callbackFunction(message.c_str(), static_cast<int>(severity), callback.userData);
callback.callbackFunction(message, static_cast<int>(severity), callback.userData);
}

auto Logging::GetLoggingCallback() -> UserCallback
Expand Down
9 changes: 9 additions & 0 deletions src/libprojectM/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class Logging
*/
PROJECTM_CXX_EXPORT static void Log(const std::string& message, LogLevel severity);

/**
* @brief Passes a log message with the given severity to the active thread or global callback.
* This overload avoids implicit string allocations.
* If no callbacks are registered, this function does nothing.
* @param message Null-terminated C string message
* @param severity LogLevel severity
*/
PROJECTM_CXX_EXPORT static void Log(const char* message, LogLevel severity);

/**
* The default log level used if no log level is set (LogLevel::Information)
*/
Expand Down
11 changes: 11 additions & 0 deletions src/libprojectM/ProjectMCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <projectM-4/parameters.h>
#include <projectM-4/render_opengl.h>

#include <exception>

#include <cstring>
#include <sstream>

Expand Down Expand Up @@ -76,6 +78,8 @@ projectm_handle projectm_create()

projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
{
using libprojectM::Logging;

try
{
// Init resolver to discover gl function pointers (guarded internally, valid to call multiple times)
Expand All @@ -95,8 +99,15 @@ projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const c
auto* projectMInstance = new libprojectM::projectMWrapper();
return reinterpret_cast<projectm_handle>(projectMInstance);
}
catch (const std::exception& e)
{
LOG_ERROR("projectm_create_with_opengl_load_proc caught exception:");
LOG_ERROR(e.what());
return nullptr;
}
Comment thread
Bert0ns marked this conversation as resolved.
catch (...)
{
LOG_ERROR("projectm_create_with_opengl_load_proc caught unknown exception");
return nullptr;
}
}
Expand Down