JuliaMultimedia / SimpleDirectMediaLayer.jl

SDL2
MIT License
81 stars 18 forks source link

SegFault when drawing text #72

Closed mpeters2 closed 10 months ago

mpeters2 commented 10 months ago

MacOS 14.0 (ARM64) Julia 1.9.3

I've tried multiple examples, and all crash with a seg fault (11) when calling either, TTF_RenderUTF8_Blended(), TTF_RenderText_Solid(), and TTF_RenderUNICODE_Solid().

Sample Code:

using SimpleDirectMediaLayer
using SimpleDirectMediaLayer.LibSDL2
using SDL2_ttf_jll

function flip(renderer::Ptr{SDL_Renderer})
    SDL_RenderPresent(renderer)
    SDL_PumpEvents()
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255)
    SDL_RenderClear(renderer)           
end

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 16)          # the number of multisample anti-aliasing buffers.
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16)          # the number of samples used around the current pixel used for multisample anti-aliasing

@assert SDL_Init(SDL_INIT_EVERYTHING) == 0 "error initializing SDL: $(unsafe_string(SDL_GetError()))"
@assert TTF_Init() == 0 "error initializing TTF_Init: $(unsafe_string(SDL_GetError()))"

winPtr = SDL_CreateWindow("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 1000, SDL_WINDOW_SHOWN)

renderer = SDL_CreateRenderer(winPtr, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)

mRect = SDL_Rect(250, 150, 200, 200)
SDL_RenderFillRect( renderer, Ref{SDL_Rect}(mRect))     # that addition mess lets me send the rect as a pointer to the rect
flip(renderer)
SDL_Delay(1000)

Sans = TTF_OpenFont("Sans.ttf", 24);
White = SDL_Color(255, 255, 255, 255)
sf = TTF_RenderUTF8_Blended(Sans, "hello world", White)
flip(renderer)

It crashes right at TTF_RenderUTF8_Blended. Crash sample:

[47951] signal (11.2): Segmentation fault: 11
in expression starting at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/debugger/run_debugger.jl:10
TTF_SizeUTF8_Internal at /Users/BobsAccount/.julia/artifacts/f4b1701fba3f3038f437274c8d136772963cd9ec/lib/libSDL2_ttf-2.0.0.dylib (unknown line)
TTF_RenderUTF8_Blended at /Users/BobsAccount/.julia/artifacts/f4b1701fba3f3038f437274c8d136772963cd9ec/lib/libSDL2_ttf-2.0.0.dylib (unknown line)
##compiled_ccall#304 at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/optimize.jl:346
unknown function (ip: 0x28e754067)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_f__call_in_world at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
do_apply at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
#invoke_in_world#3 at ./essentials.jl:853
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
do_apply at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
invoke_in_world at ./essentials.jl:850
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
do_apply at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
bypass_builtins at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:195
#evaluate_call_recurse!#65 at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:222
evaluate_call_recurse! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:220 [inlined]
eval_rhs at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:393
step_expr! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:557
step_expr! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:607
finish! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:14
finish_and_return! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:30
#evaluate_call_recurse!#65 at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:260
evaluate_call_recurse! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:220 [inlined]
eval_rhs at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:393
step_expr! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:552
step_expr! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/interpret.jl:607 [inlined]
next_until! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:92
_next_line! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:181 [inlined]
next_line! at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:176
#debug_command#86 at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:467
debug_command at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/JuliaInterpreter/src/commands.jl:448
jfptr_debug_command_1033 at /Users/BobsAccount/.julia/compiled/v1.9/VSCodeDebugger/xYOi8_cFusM.dylib (unknown line)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_f__call_latest at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
#invokelatest#2 at ./essentials.jl:819 [inlined]
invokelatest at ./essentials.jl:816 [inlined]
our_debug_command at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/DebugAdapter/src/debugger_core.jl:67
startdebug at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/DebugAdapter/src/packagedef.jl:108
startdebugger at /Users/BobsAccount/.vscode/extensions/julialang.language-julia-1.61.2/scripts/packages/VSCodeDebugger/src/VSCodeDebugger.jl:43
unknown function (ip: 0x11309445f)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
do_call at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
eval_body at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_interpret_toplevel_thunk at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_toplevel_eval_flex at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_toplevel_eval_flex at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
ijl_toplevel_eval_in at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
eval at ./boot.jl:370 [inlined]
include_string at ./loading.jl:1903
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
_include at ./loading.jl:1963
include at ./Base.jl:457
jfptr_include_29526 at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
exec_options at ./client.jl:307
_start at ./client.jl:522
jfptr__start_51456 at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
true_main at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
jl_repl_entrypoint at /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.9.dylib (unknown line)
Allocations: 9495066 (Pool: 9487246; Big: 7820); GC: 13

Strangely, I can get GameZero to work and draw text, and I've audited their function calls, and they look identical to mine, yet it does not crash.

mpeters2 commented 10 months ago

Mea culpa: I never noticed that the pointer to the font was null. It turns out that the file path in VScode was pointing to the wrong folder, and so the font was never loaded.