Skip to content

Attempt to fix: font not set error when cast bars are enabled#871

Open
monolitas wants to merge 1 commit intoElvUI-WotLK:masterfrom
monolitas:fix-font-not-set-error
Open

Attempt to fix: font not set error when cast bars are enabled#871
monolitas wants to merge 1 commit intoElvUI-WotLK:masterfrom
monolitas:fix-font-not-set-error

Conversation

@monolitas
Copy link
Copy Markdown

**bug fix for: #482
When cast bars are enabled, the UI throws a "SetText" error

Copilot AI review requested due to automatic review settings September 11, 2025 09:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a "Font not set" error that occurs when cast bars are enabled in the nameplate module during initialization. The fix adds safeguards to ensure fonts are properly set before attempting to display text on cast bar elements.

  • Adds conditional logic to only manipulate test cast bars when any cast bar is enabled in settings
  • Implements font validation and fallback assignment before setting text
  • Adds nil checks for cast bar elements before accessing their properties

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +1245 to +1250
local anyCastbarEnabled = unitsDB and (
(unitsDB.ENEMY_PLAYER and unitsDB.ENEMY_PLAYER.castbar and unitsDB.ENEMY_PLAYER.castbar.enable) or
(unitsDB.ENEMY_NPC and unitsDB.ENEMY_NPC.castbar and unitsDB.ENEMY_NPC.castbar.enable) or
(unitsDB.FRIENDLY_PLAYER and unitsDB.FRIENDLY_PLAYER.castbar and unitsDB.FRIENDLY_PLAYER.castbar.enable) or
(unitsDB.FRIENDLY_NPC and unitsDB.FRIENDLY_NPC.castbar and unitsDB.FRIENDLY_NPC.castbar.enable)
) or false
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The repeated pattern for checking castbar.enable across different unit types creates duplicated logic. Consider extracting this into a helper function or using a loop over unit types to reduce code duplication.

Suggested change
local anyCastbarEnabled = unitsDB and (
(unitsDB.ENEMY_PLAYER and unitsDB.ENEMY_PLAYER.castbar and unitsDB.ENEMY_PLAYER.castbar.enable) or
(unitsDB.ENEMY_NPC and unitsDB.ENEMY_NPC.castbar and unitsDB.ENEMY_NPC.castbar.enable) or
(unitsDB.FRIENDLY_PLAYER and unitsDB.FRIENDLY_PLAYER.castbar and unitsDB.FRIENDLY_PLAYER.castbar.enable) or
(unitsDB.FRIENDLY_NPC and unitsDB.FRIENDLY_NPC.castbar and unitsDB.FRIENDLY_NPC.castbar.enable)
) or false
local unitTypes = { "ENEMY_PLAYER", "ENEMY_NPC", "FRIENDLY_PLAYER", "FRIENDLY_NPC" }
local anyCastbarEnabled = false
if unitsDB then
for _, unitType in ipairs(unitTypes) do
local unit = unitsDB[unitType]
if unit and unit.castbar and unit.castbar.enable then
anyCastbarEnabled = true
break
end
end
end

Copilot uses AI. Check for mistakes.
Comment on lines +1257 to +1262
if castbar.Name and not select(1, castbar.Name:GetFont()) then
castbar.Name:SetFontObject(GameFontNormal)
end
if castbar.Time and not select(1, castbar.Time:GetFont()) then
castbar.Time:SetFontObject(GameFontNormal)
end
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The font checking and setting logic is duplicated for both Name and Time elements. This could be extracted into a helper function that takes the text element as a parameter to reduce code duplication.

Suggested change
if castbar.Name and not select(1, castbar.Name:GetFont()) then
castbar.Name:SetFontObject(GameFontNormal)
end
if castbar.Time and not select(1, castbar.Time:GetFont()) then
castbar.Time:SetFontObject(GameFontNormal)
end
local function EnsureFontSet(textElement)
if textElement and not select(1, textElement:GetFont()) then
textElement:SetFontObject(GameFontNormal)
end
end
EnsureFontSet(castbar.Name)
EnsureFontSet(castbar.Time)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants