aviks / GameZero.jl

Zero overhead game development library for the Julia programming language
Other
184 stars 23 forks source link

Too many open files error #55

Open DhruvaSambrani opened 2 years ago

DhruvaSambrani commented 2 years ago
Base.IOError("readdir(\"./images\"): too many open files (EMFILE)", -24)

I made my own version of the flappy bird game, and I face this issue if I play it for a while. It looks like GameZero is not GC-ing some images(?)

Note, I change the bird image everytime I press space, and for a game like flappy bird, that is quite often. I thought the image will be reused?

DhruvaSambrani commented 2 years ago

Also, ALSA lib conf.c:4563:(snd_config_update_r) cannot access file /usr/share/alsa/alsa.conf pops up just before this error is thrown. Note that I have applied the fix as suggested in #42, and audio works well until this error.

levje commented 1 year ago

Hi. I'm having the same problem with fonts. It seems like the following function loads a new instance of the same font file every time we create a new TextActor. The second line of the function creates a new TextActor and it never closes the TextActor.


function TextActor(text::String, font_name::String; font_size=24, color=Int[255,255,0,255], kv...)
    font = TTF_OpenFont(file_path(font_name, :fonts), font_size)
    sf = TTF_RenderText_Blended(font, text, SDL_Color(color...))
    w, h = size(sf)
    a = Actor(
        text, 
        sf, 
        Rect(0, 0, Int(w), Int(h)), 
        [1.,1.], 
        0,
        255,
        Dict{Symbol,Any}()
    )

    for (k, v) in kv
        setproperty!(a, k, v)
    end
    return a
end```
aviks commented 1 year ago

@MrZarfir good find. Can you try adding a TTF_CloseFont(font) call after the sf = TTF_Render_Text(...) call and test if your problem goes away?

levje commented 1 year ago

@MrZarfir good find. Can you try adding a TTF_CloseFont(font) call after the sf = TTF_Render_Text(...) call and test if your problem goes away?

Indeed, my problem goes away after adding a closing call. I don't have access to push the new change to a new branch, but it would be appreciated if you can add this small change (unless you can give me access so I can push it).

Thank you for your quick response.

aviks commented 1 year ago

don't have access to push the new change to a new branch

@MrZarfir You don't need push access to collaborate on an open source repository. You typically create a fork, and make a pull request from there. See this github documentation

Hower, in this case, I have created this pull request here: #64