Crashing Mini Menu Fix (Unregister Event Handler) (#1328)
* Adding unregister event handler, and removing during button layout screen shutdown() * Updating cmake version * bss pointed this out, should be 3.13 not 3.5 * Testing ubuntu roll-back * Reverting back to 22.04 * Attempting to downgrade cmake to 3.16.x
This commit is contained in:
2
.github/workflows/cmake.yml
vendored
2
.github/workflows/cmake.yml
vendored
@@ -76,7 +76,7 @@ jobs:
|
||||
cmake-version: '3.16.x'
|
||||
- name: Verify cmake
|
||||
run: cmake --version
|
||||
|
||||
|
||||
#Global Setup
|
||||
- name: Checkout GP2040-CE
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
@@ -40,11 +40,12 @@ class EventManager {
|
||||
void clearEventHandlers();
|
||||
|
||||
void registerEventHandler(GPEventType eventType, EventFunction handler);
|
||||
void unregisterEventHandler(GPEventType eventType, EventFunction handler);
|
||||
void triggerEvent(GPEvent* event);
|
||||
private:
|
||||
EventManager(){}
|
||||
|
||||
std::vector<std::pair<GPEventType, std::vector<EventFunction>>> eventList;
|
||||
std::vector<EventEntry> eventList;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -85,6 +85,10 @@ void ButtonLayoutScreen::init() {
|
||||
|
||||
void ButtonLayoutScreen::shutdown() {
|
||||
clearElements();
|
||||
|
||||
EventManager::getInstance().unregisterEventHandler(GP_EVENT_PROFILE_CHANGE, GPEVENT_CALLBACK(this->handleProfileChange(event)));
|
||||
EventManager::getInstance().unregisterEventHandler(GP_EVENT_USBHOST_MOUNT, GPEVENT_CALLBACK(this->handleUSB(event)));
|
||||
EventManager::getInstance().unregisterEventHandler(GP_EVENT_USBHOST_UNMOUNT, GPEVENT_CALLBACK(this->handleUSB(event)));
|
||||
}
|
||||
|
||||
int8_t ButtonLayoutScreen::update() {
|
||||
|
||||
@@ -18,6 +18,21 @@ void EventManager::registerEventHandler(GPEventType eventType, EventFunction han
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::unregisterEventHandler(GPEventType eventType, EventFunction handler) {
|
||||
typename std::vector<EventEntry>::iterator it = std::find_if(eventList.begin(), eventList.end(), [&eventType](const EventEntry& entry) { return entry.first == eventType; });
|
||||
|
||||
// Verify we have this event in our pair list
|
||||
if (it != eventList.end()) {
|
||||
// Verify we have this function in our function vector
|
||||
for(std::vector<EventFunction>::iterator funcIt = it->second.begin(); funcIt != it->second.end(); it++){
|
||||
if(*(uint32_t *)(uint8_t *)&handler == *(uint32_t *)(uint8_t *)&(*funcIt)) {
|
||||
it->second.erase(funcIt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::triggerEvent(GPEvent* event) {
|
||||
GPEventType eventType = event->eventType();
|
||||
for (typename std::vector<EventEntry>::const_iterator it = eventList.begin(); it != eventList.end(); ++it) {
|
||||
|
||||
Reference in New Issue
Block a user