From a0cee2ce2baaf25afe8e1459d7e1c37cb2a7af72 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 11 Jul 2026 02:57:34 -0500 Subject: [PATCH] Maintain a list of created virtual controllers in the OpenRGBPluginAPI object and only allow registering virtual controllers that exist in this list --- OpenRGBPluginAPI.cpp | 33 +++++++++++++++++++++++++++++++++ OpenRGBPluginAPI.h | 1 + 2 files changed, 34 insertions(+) diff --git a/OpenRGBPluginAPI.cpp b/OpenRGBPluginAPI.cpp index bba233717..263752ad5 100644 --- a/OpenRGBPluginAPI.cpp +++ b/OpenRGBPluginAPI.cpp @@ -41,6 +41,12 @@ RGBControllerInterface* OpenRGBPluginAPI::CreateVirtualRGBController(RGBControll { RGBController_Virtual* rgb_controller = new RGBController_Virtual(setup); + /*-----------------------------------------------------*\ + | Add the new controller to the list of created | + | controllers | + \*-----------------------------------------------------*/ + created_controllers.push_back((RGBController*)rgb_controller); + return(rgb_controller); } @@ -63,6 +69,27 @@ void OpenRGBPluginAPI::RegisterVirtualRGBController(RGBControllerInterface* rgb_ { LOG_INFO("[PluginManager] Registering RGB controller %s", rgb_controller->GetName().c_str()); + /*-----------------------------------------------------*\ + | Ensure the pointer given is a pointer to a valid | + | virtual controller | + \*-----------------------------------------------------*/ + bool found = false; + + for(std::size_t controller_idx = 0; controller_idx < created_controllers.size(); controller_idx++) + { + if(created_controllers[controller_idx] == rgb_controller) + { + found = true; + break; + } + } + + if(!found) + { + LOG_ERROR("[PluginManager] Attempted to register an RGBController that was not created by this plugin API instance."); + return; + } + /*-----------------------------------------------------*\ | Mark this controller as locally owned | \*-----------------------------------------------------*/ @@ -131,6 +158,12 @@ void OpenRGBPluginAPI::UpdateVirtualRGBController(RGBControllerInterface* rgb_co void OpenRGBPluginAPI::DeleteVirtualRGBController(RGBControllerInterface* rgb_controller) { + /*-----------------------------------------------------*\ + | Remove the controller from the list of created | + | controllers | + \*-----------------------------------------------------*/ + created_controllers.erase(std::remove(created_controllers.begin(), created_controllers.end(), (RGBController*)rgb_controller), created_controllers.end()); + delete (RGBController*)rgb_controller; } diff --git a/OpenRGBPluginAPI.h b/OpenRGBPluginAPI.h index f0433ebbf..4ec2a86fb 100644 --- a/OpenRGBPluginAPI.h +++ b/OpenRGBPluginAPI.h @@ -67,6 +67,7 @@ public: /*-----------------------------------------------------*\ | RGBControllers registered by plugin | \*-----------------------------------------------------*/ + std::vector created_controllers; std::vector rgb_controllers; private: