Skip to content

Conversation

@rempack-b
Copy link
Contributor

I have finally figured out the issues preventing me from using the single-header rmkit across multiple TUs.

There were a few namespace-level global static variables. If such variables are not extern or inline, each TU will get their own uninitialized copy of the field.

This resulted in a build that throws no warnings at all, but segfaults at runtime when we try to read a null font, or the FB singleton is empty and we get no render.

I've used extern instead of inline because rmkit's build process complains about inline and there are already other fields with extern and that clever initializer generation. There should be no difference between the two, but inline is only in C++>=17

I think these were the only such fields left in rmkit. My application seems to work fine now with these changes.

I had to learn a lot about C++ to figure this out, so here's what I've got:
The only problems are namespace-level static variables and static variables within an inlined function. Static variables at the class/struct level work as you'd expect across TUs. Static and inline functions are also fine and work as expected, so long as they don't touch local static or namespace-static variables.

@raisjn
Copy link
Member

raisjn commented Jul 4, 2025

thanks for doing this and sorry for the trouble, hopefully your compile times are much faster now with this fixed

are you able to update this branch to latest so the PR build works? thank you!

@raisjn raisjn merged commit fc372b2 into rmkit-dev:master Jul 4, 2025
1 check passed
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.

3 participants