esdl2 icon indicating copy to clipboard operation
esdl2 copied to clipboard

hello_sdl demo minor fixes

Open brainstormi opened this issue 9 years ago • 3 comments

Minor fixes around hello_sdl demo.

brainstormi avatar Dec 26 '15 22:12 brainstormi

Sorry, I think i mixed this pull request with my previous ones... dummy here!. Trying to see how can I do it correctly.

brainstormi avatar Dec 26 '15 22:12 brainstormi

It's OK, it will be fine once I merge the other ones. Worst case I can cherry-pick I'm sure.

essen avatar Dec 26 '15 22:12 essen

After applied all the commits inside this PR, a new segfault issue could appears randomly when destroying renderer. To replicate it, it's enough modify hello_sdl source demo in the following way: init() -> ok = sdl:start([video]), ok = sdl:stop_on_exit(), {ok, Window} = sdl_window:create("Hello SDL", 10, 10, 500, 500, []), {ok, Renderer} = sdl_renderer:create(Window, -1, [accelerated, present_vsync]), loop(#{window=>Window}).

loop(State) -> events_loop(), loop(State).

In OSX it segfaults in dtor_Renderer function most of the times it's executed, when invoking enif_release_resource(...); in Windows it's more difficult to replicate, although it happens if you retry it enough times. With some printf debugging it seems that resource pointer to Renderer gets corrupted randomly, usually after SDL_DestroyRenderer call, but less frequently call to NIF_RES_DEP before SDL_DestroyRenderer already shows an invalid pointer. In any case, dtor_Windows never is invoked before the segfault.

Funny thing, is that if we avoid invoking loop(#{XXXX}) inside init() function in hello_sdl, this doesn't happens, but really I don't know why.

I'll open a new issue if commits are finally merged due to the differences how dtor_XXX works in current master brach (although i'll bet it should be suffering the same issue).

EDIT: It seems this is a quite exceptional seg fault, I can only replicate it with the previous example. In usual conditions when something is rendered to the screen I'm not able to replicate it at the moment. it could be some timing issue with SDL2 or with running sdl_events:poll inside a loop when renderer is destroyed just after being initialized.

brainstormi avatar Dec 27 '15 17:12 brainstormi