<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 25 Mar 2019 at 09:13, Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, 23 Mar 2019 14:28:16 +0100<br>
Sylvain Becker <<a href="mailto:sylvain.becker@gmail.com" target="_blank">sylvain.becker@gmail.com</a>> wrote:<br>
<br>
> Hi,<br>
> <br>
> There is a crash when an SDL2 game (Exult), using KMS-DRM back-end,<br>
> terminates.<br>
> It appears in GBM (gbm_device_destroy()), there migh be also invalid access<br>
> in egl datas.<br>
> <br>
> SDL2 issue can be found at <a href="https://bugzilla.libsdl.org/show_bug.cgi?id=4530" rel="noreferrer" target="_blank">https://bugzilla.libsdl.org/show_bug.cgi?id=4530</a><br>
> (with a very small test case)<br>
> Exult game at <a href="https://github.com/exult" rel="noreferrer" target="_blank">https://github.com/exult</a><br>
> <br>
> It occurs because:<br>
> - Mesa uses atexit()<br>
> - Exult game also chooses atexit() to clean up SDL2 internals. (e.g<br>
> atexit(SDL_Quit))<br>
> <br>
> Depending on how atexit callbacks are sorted/registered :<br>
> - Mesa cleans up first GBM with an atexit().<br>
> - If SDL2 tries to clean up things once again and it crashes.<br>
> <br>
> This is reported for SDL2, but any layer using atexit() and GBM could<br>
> reproduce the same crash.<br>
> <br>
> There are surely several ways to avoid this, but I wonder what you would<br>
> advice to solve this.<br>
<br>
Hi,<br>
<br>
my personal opinion is that the use of atexit() is almost always a bad<br>
idea, both for the app and Mesa. I'm not a Mesa developer and I don't<br>
know why Mesa wanted to use it, but I can imagine it is a compromise<br>
between bad choices - I'm sure they know the caveats of atexit(). Your<br>
problem is a good example of why atexit() should not be used at all.<br>
<br>
It should be much easier to make the game not use atexit(), because it<br>
controls the application main event loop, than Mesa which has no<br>
knowledge of any main loop and therefore cannot reasonably hook up to<br>
its exit sequence on its own.<br>
<br>
<br>
Thanks,<br>
pq<br>
</blockquote></div><div><br></div><div>Hi,</div><div>Thanks for your answer. Indeed not using atexit() is the easiest way.</div><div>I wish I had an API to detect the library has been terminated.</div><div><br></div><div>Thanks,</div><div><div dir="ltr" class="gmail_signature">Sylvain<br></div></div></div>