Skip to content

chore(color): refactor window close / delete logic - #7804

Open
philmoz wants to merge 2 commits into
mainfrom
philmoz/refactor-window-delete
Open

philmoz wants to merge 2 commits into
mainfrom
philmoz/refactor-window-delete

Conversation

@philmoz

@philmoz philmoz commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Currently window closure and deletion logic on color radios is handled through:

  • the 'deleteLater' virtual function on the Window class. This is called when a window is being closed. It is overridden in derived classes to handle any class specific cleanup required. Derived class functions are required to always call the parent class 'deleteLater' function, failing to do this will result in memory leaks and possible crashes. Eventually this will call back to the base Window class 'deleteLater' function which handles deleting child objects, popping layers, calling custom close handler functions and adding the Window pointer to the 'trash' list for later destruction.
  • the 'closeHandler' function. In contrast to 'deleteLater' which operates on every instance of a class, this can be set for a specific instance to perform cleanup when that instance is closed.
  • the 'trash'. This is a list of Window pointers that have been closed; but not destroyed. Once per main loop, after all of the events have been handled, every Window in the trash is destroyed and the trash is cleared.

Apart from the issues that can occur if 'deleteLater' does not call its parent, the order of Window closure is dependent on how each 'deleteLater' function is coded and is somewhat non-deterministic. The 'deleteLater' and closeHandler code may also check if the window has already been closed to prevent recursive loops.

This PR replaces this with the following:

  • derived classes that require extra logic when closing call the 'onClosing()' method in their constructor to register the code to be called
  • instances of a class can call instance->onClosing() to also register logic to be called when that instance is closed
  • every code block registered with onClosing() is added to a list of close handlers
  • 'deleteLater' has been renamed 'closeWindow' and is no longer a virtual function. When called this now 1) recursively closes all child windows in reverse order of creation, 2) calls all the close handler code registered with onClosing() in reverse order of creation, 3) pops the window layer if needed and adds the window to the trash
  • trash handling remains the same

For any window closure logic, this removes the need to call parent class virtual functions, removes the need to check if a window has already been deleted, and makes the order of closure deterministic.

@philmoz philmoz added this to the 3.0 milestone Sep 17, 2026
@philmoz philmoz added color Related generally to color LCD radios UX-UI Related to user experience (UX) or user interface (UI) behaviour house keeping 🧹 Cleanup of code and house keeping firmware (fw) General radio firmware issue, not colorlcd or B&W specific labels Sep 17, 2026
@philmoz
philmoz force-pushed the philmoz/refactor-window-delete branch from eab7ae3 to b574f5d Compare September 18, 2026 04:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

color Related generally to color LCD radios firmware (fw) General radio firmware issue, not colorlcd or B&W specific house keeping 🧹 Cleanup of code and house keeping UX-UI Related to user experience (UX) or user interface (UI) behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant