Skip to content

Commit c58df2f

Browse files
committed
Fixes loading for builds
Ensures images and fonts are loaded correctly when the project is compiled. Specifically, it checks if the application is running in a compiled package before attempting to load images from the standard file system path. Also it now loads the default font correctly when font path is empty or "Default".
1 parent 67e10a5 commit c58df2f

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/engine/Component/Sprite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ module SpriteModule
213213
function Component.load_image(this::InternalSprite, imagePath::String)
214214
SDL2.SDL_ClearError()
215215

216-
if !isfile(joinpath(BasePath, "assets", "images", imagePath))
216+
if !JulGame.IS_PACKAGE_COMPILED && isfile(joinpath(BasePath, "assets", "images", imagePath))
217217
@error("Image file does not exist: $(imagePath)")
218218
this.image = load_fallback_image()
219219
setfield!(this, :imagePath, "fallback.png")

src/engine/UI/TextBox.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ module TextBoxModule
161161

162162
this.font = load_font_sdl(basePath, fontPath, trueFontSize)
163163
if this.font == C_NULL
164-
error("Failed to load font, $(unsafe_string(SDL2.SDL_GetError()))")
165-
return
164+
error("Failed to load font, $(unsafe_string(SDL2.SDL_GetError())), loading default font")
165+
this.fontPath = "Default"
166+
this.font = CallSDLFunction(SDL2.TTF_OpenFontRW, SDL2.SDL_RWFromConstMem(pointer(JulGame.BUILT_IN_ASSETS["Font"]), length(JulGame.BUILT_IN_ASSETS["Font"])), 1, Math.TypeConversions.safe_int32_convert(fontSize))
166167
end
167168
if fontPath != "Default"
168169
this.fontPath = fontPath
@@ -218,8 +219,8 @@ module TextBoxModule
218219
end
219220

220221
function load_font_sdl(basePath::String, fontPath::String, fontSize::Int)
221-
if haskey(JulGame.FONT_CACHE, get_comma_separated_path(fontPath)) || fontPath == "Default"
222-
if fontPath == "Default"
222+
if haskey(JulGame.FONT_CACHE, get_comma_separated_path(fontPath)) || fontPath == "Default" || fontPath == ""
223+
if fontPath == "Default" || fontPath == ""
223224
raw_data = JulGame.BUILT_IN_ASSETS["Font"]
224225
@debug "loading default font"
225226
else
@@ -234,10 +235,7 @@ module TextBoxModule
234235
end
235236
end
236237
@debug "Loading font from disk, there are $(length(JulGame.FONT_CACHE)) fonts in cache"
237-
if fontPath == ""
238-
@debug "fontPath is empty, using default font"
239-
fontPath = joinpath("FiraCode-Regular.ttf")
240-
end
238+
241239
return CallSDLFunction(SDL2.TTF_OpenFont, joinpath(basePath, fontPath), Math.TypeConversions.safe_int32_convert(fontSize))
242240
end
243241

0 commit comments

Comments
 (0)