fix(w3d): guard against null bold font in W3DDisplayString::setFont#2893
fix(w3d): guard against null bold font in W3DDisplayString::setFont#2893bobtista wants to merge 3 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp | Adds null guard for bold font lookup in setFont; fix is correct and mirrors the null-tolerance pattern already present in the function. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp | Identical null guard applied to the Zero Hour variant; change is in sync with the Generals copy. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["W3DDisplayString::setFont(font)"] --> B{font == nullptr?}
B -- Yes --> C[return early]
B -- No --> D{m_font == font?}
D -- Yes --> E[return early, no-op]
D -- No --> F["DisplayString::setFont(font)"]
F --> G["m_textRenderer.Set_Font(m_font->fontData)"]
G --> H["boldFont = TheFontLibrary->getFont(name, size, TRUE)"]
H --> I{boldFont != nullptr?}
I -- "Yes (normal mode)" --> J["m_textRendererHotKey.Set_Font(boldFont->fontData)"]
I -- "No (headless/no display resources)" --> K["skip hotkey renderer — no crash"]
J --> L["computeExtents()"]
K --> L
L --> M["m_fontChanged = TRUE"]
Reviews (2): Last reviewed commit: "fix(w3d): Simplify null bold font guard" | Re-trigger Greptile
|
This is a third PR that references a closed PR. As I mentioned in of the other PR's, I highly disagree with the process first. This should have been an issue first (unable to save in headless), that should have had three subissues outlining three different problems why saving in headless was not possible. The scope is too blurry now. Do these three PR's combined fix the problem? |
At the time I made the PR these were based on, there was a crash, but since then, other PRs were merged and the crash no longer happens. This is a good guard to have, but there's no issue for it to resolve - want me to just close it? |
W3DDisplayString::setFont dereferences the result of TheFontLibrary->getFont() for the bold hotkey font without a null check. getFont can return null when font loading fails in headless mode where no display resources exist, and the game crashes as soon as a display string receives a font.
Now setFont only sets the hotkey renderer font when the bold font lookup succeeds, matching the null tolerance at the top of the function.
Todo: