Add function to unregister update callback when device page is deleted

This commit is contained in:
Adam Honse 2020-08-19 21:43:47 -05:00
parent 63f005d4fc
commit 342d90b82a
3 changed files with 17 additions and 1 deletions

View file

@ -1334,6 +1334,20 @@ void RGBController::RegisterUpdateCallback(RGBControllerCallback new_callback, v
UpdateCallbackArgs.push_back(new_callback_arg);
}
void RGBController::UnregisterUpdateCallback(void * callback_arg)
{
for(unsigned int callback_idx = 0; callback_idx < UpdateCallbackArgs.size(); callback_idx++ )
{
if(UpdateCallbackArgs[callback_idx] == callback_arg)
{
UpdateCallbackArgs.erase(UpdateCallbackArgs.begin() + callback_idx);
UpdateCallbacks.erase(UpdateCallbacks.begin() + callback_idx);
break;
}
}
}
void RGBController::SignalUpdate()
{
UpdateMutex.lock();

View file

@ -192,6 +192,7 @@ public:
void SetSingleLEDColorDescription(unsigned char* data_buf);
void RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg);
void UnregisterUpdateCallback(void * callback_arg);
void SignalUpdate();
void UpdateLEDs();

View file

@ -8,7 +8,7 @@ static void UpdateCallback(void * this_ptr)
{
OpenRGBDevicePage * this_obj = (OpenRGBDevicePage *)this_ptr;
//QMetaObject::invokeMethod(this_obj, "UpdateInterface", Qt::QueuedConnection);
QMetaObject::invokeMethod(this_obj, "UpdateInterface", Qt::QueuedConnection);
}
OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
@ -97,6 +97,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
OpenRGBDevicePage::~OpenRGBDevicePage()
{
device->UnregisterUpdateCallback(this);
delete ui;
}