Skip to content

Fixed alignment issue for draw commands#81

Open
jackss011 wants to merge 2 commits intorxi:masterfrom
jackss011:fix/cmd-alignment
Open

Fixed alignment issue for draw commands#81
jackss011 wants to merge 2 commits intorxi:masterfrom
jackss011:fix/cmd-alignment

Conversation

@jackss011
Copy link
Copy Markdown

@jackss011 jackss011 commented Jan 6, 2026

This PR is supposed to be a fix for:

Solution

The fix consists in storing commands in a mu_stack(mu_Commands, ...) rather in a mu_stack(char, ...).
In order to achieve this mu_TextCommands.str strings are stored in a separate mu_stack(char, ...) called ctx->command_txt, so that mu_Command(s) can be considered of fixed size sizeof(mu_Command) = 32.

image

Text command strings can still be accessed via cmd->text.str which is now a char* that points to the buffer of ctx->command_txt which will end up containing a list of \0 separated strings (i.e. the text commands contain a pointer to the beginning of the string). This stack is reset together with ctx->command_list inside mu_begin(...).

The mu_Command union was updated to fix #80 by making sure all command variants share the same initial type field.

image

Advantages

  • this solution is likely to have less unexpected behaviors on different architectures since it simply uses an array of tagged unions
  • it removes the "sketchiness" of having to write out of buffer on a char[1] and relying on an external size field to keep track of how much you went out of buffer

Drawbacks

1. More wasted space

  • commands are all padded to 32, when previously where stored as the their actual size
  • ctx->commands_txt is extra wasted space (of 2048 bytes by default)

Answer
I assumed that minimizing memory usage is a NOT priority for this library since a lot its type definitions use int or void* rather than a 100% viable smaller version:

  • mu_Command.type could be a uint8_t
  • mu_Font could be a uint8_t as the index of a global font info table
  • mu_Vec2 and mu_Rect could use int16_ts since they represent pixel coordinates

Also all the rendered strings that are not changed during the execution have no reason to be copied into the command buffer (or any buffer) but could simply be referenced by pointer (this PR makes this potential mu_draw_text_static(ctx, const char*) feature super easy to implement since the mu_TextCommand now uses a char *)

Braking Changes

  • cmd->type no longer works, use cmd->base.type instead

@jackss011 jackss011 marked this pull request as ready for review January 6, 2026 20:28
@awschult002
Copy link
Copy Markdown

there has been a new community fork of this repository. the community is looking to add some new simple features. please feel free to try your PR over there.

https://github.com/microui-community/microui

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.

mu_Command invokes undefined behavior.

2 participants