Skip to content

Improve native Gui code quality - #302

Open
nhjschulz wants to merge 14 commits into
BlueAndi:Developmentfrom
nhjschulz:fix/native_improvements
Open

nhjschulz wants to merge 14 commits into
BlueAndi:Developmentfrom
nhjschulz:fix/native_improvements

Conversation

@nhjschulz

@nhjschulz nhjschulz commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Add code quality and small fixes after extensive review of recently added code.

Fixes:

  • LedGridSim now "owns" the SDL interface, avoiding life time and allocation issues.
  • Guard against broken resolution settings that may lead to a zero divide for aspect ratio.
  • Fixed shutdown path to reset init flags. It can now safely called repetitively.
  • Changed unnecessary use of MenuPopup() in favor of MenuItem()

Cosmetics:

  • Align with code templates (some sections in files where missing or wrongly use)
  • Update stale comments
  • Removed dead/redundant code
  • Changed snake-case variables to camel-case
  • Made methods const where possible.

@nhjschulz
nhjschulz requested a review from BlueAndi October 6, 2026 08:17
@nhjschulz nhjschulz self-assigned this Oct 6, 2026
/**
* @brief Initializes SDL and creates the window and renderer.
* @brief Initializes UI and creates the window and renderer.
* @param[in] width The width of the LED matrix in LEDs.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in pixels

@nhjschulz nhjschulz Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the other was wrong. On LedGridSim layer we calculate with the grid resolution, on SDLInterface, its pixels.

Comment thread lib/HalLedMatrixNative/src/LedGridSim.h Outdated
bool initialize(int width, int height);

/**
* @brief Release IMGUI resources.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release internal resources ... what is the consequence?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect real consequences, assuming Linux and WIndow tidy up on app exit in any case. But both ImGui and SDL layer allocate objects on the heap and also for SDL in GPU ram (i.e. Surfaces, Textures ...).

I changes the comment to this to be more specific:

 * @brief Release IMGUI/SDL owned heap/GPU resources.

Comment thread lib/HalLedMatrixNative/src/SDLInterface.cpp Outdated
shutdown();
}

bool LedGridSim::initialize(int width, int height)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must it be int or could it be uint16_t with the advantage to avoid casting later.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to uint16_t. The int promoted from SDL upwards where coordinates are int (negative is used for off screen). But SDL is an internal part and should not impact outgoing interfaces.

The change did impact range checking and casts move to the SDL call now.

Same object was deleted twice, likely copy+paste error.
Use a static SdlInterface instance instead of heap allocation.
There is no need for heap allocation as this object is alive
for the entire execution time. No nullptr checks required now,
which had been missing before.
Add missing sections from code template to recently added cpp files.
- Release already acquired ImGui resources if a later init step failed.
- Add a "shutdown()" call to release resources on request. The
  destructor is only called on app shutdown (static object).
Don't compute buttonDriver * and aspect ratio on each update.
Calculate during init and store in class members for later access.
Make SDLInterface owned by the LedGridSim to avoid heap usage.
Fix shutdown() of LedGridSim to be robust against repetitive calls.
An empty about menu was used which means its just a MenuItem. Use
the proper classes also there is no visual diffference.
Most functions don't modify class members, mark them as const.
Some variables used snake_case.
@nhjschulz
nhjschulz force-pushed the fix/native_improvements branch from b5cf341 to 7b34b67 Compare October 6, 2026 19:23

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants