Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Nov 2007 15:25:05 +0100
From:      Christian Gusenbauer <c47g@gmx.at>
To:        freebsd-current@freebsd.org
Subject:   Crashes with SDL and libthr
Message-ID:  <200711241525.10171.c47g@gmx.at>

next in thread | raw e-mail | index | archive | help
--nextPart1208871.ufsJEfDTOy
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi!

I've just updated to today's current and now some SDL based applications ar=
e=20
crashing. I debugged a bit and found out, that the changes made to libthr a=
re=20
causing these crashes. The attached program crashes immediately using the=20
current libthr. This program does not crash when I'm using an old version o=
f=20
libthr (before 2007/11/21).

/*
compiled with:
cc -g -I/usr/local/include -L/usr/local/lib sdltest.c -lSDL -lthr -o sdltest
*/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>

#define SAMPLE_FREQ     44100
#define SAMPLE_SIZE     (512*2)

void AudioCallbackSDL(void *udata, u_int8_t *buffer, int length)
{
}

main()
{
    SDL_AudioSpec audioSpec;
    SDL_AudioSpec mySpec;

    if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO ) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }

    memset((void*)&audioSpec, 0, sizeof(SDL_AudioSpec));
    memset((void*)&mySpec, 0, sizeof(SDL_AudioSpec));

    audioSpec.freq =3D SAMPLE_FREQ;
    audioSpec.format =3D AUDIO_U8;
    audioSpec.channels =3D 1;
    audioSpec.samples =3D SAMPLE_SIZE/(44100/SAMPLE_FREQ);
    audioSpec.callback =3D AudioCallbackSDL;
    audioSpec.userdata =3D (void*)1;
    if (SDL_OpenAudio(&audioSpec, &mySpec) < 0) {
        fprintf(stderr, "can't open SDL audio: %s\n", SDL_GetError());
        exit(1);
    }

    sleep(10);
}

=2D------------------------------------------------------------------------=
=2D-

I debugged SDL and found the following piece of code, which causes the crash
in SDL_thread.c (around line 249).

        args->func =3D fn;
        args->data =3D data;
        args->info =3D thread;
        args->wait =3D SDL_CreateSemaphore(0);
                     ^
                     + here a semaphore is created with initial value 0

        if ( args->wait =3D=3D NULL ) {
                SDL_free(thread);
                SDL_free(args);
                return(NULL);
        }

        /* Add the thread to the list of available threads */
        SDL_AddThread(thread);

        /* Create the thread and go! */
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
        ret =3D SDL_SYS_CreateThread(thread, args, pfnBeginThread,=20
pfnEndThread);
#else
        ret =3D SDL_SYS_CreateThread(thread, args);
#endif
        if ( ret >=3D 0 ) {
                /* Wait for the thread function to use arguments */
                SDL_SemWait(args->wait);
                ^
                + here the calling thread should wait for the newly created
                  thread (but it doesn't)
        } else {
                /* Oops, failed.  Gotta free everything */
                SDL_DelThread(thread);
                SDL_free(thread);
                thread =3D NULL;
        }
        SDL_DestroySemaphore(args->wait);
        SDL_free(args);
        ^
        + here the args are freed, which causes the crash of the newly
          created thread. So I assume something's wrong with the semaphore
          operations

The newly created thread crashes, because he uses the args area passed as=20
parameter to the SDL_SYS_CreateThread call and the parent thread is not=20
waiting as it is supposed to.

Could someone please have a look at these libthr changes?

Many thanks,
Christian.

--nextPart1208871.ufsJEfDTOy
Content-Type: application/pgp-signature; name=signature.asc 
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQBHSDRG73Wh/GTgh8wRAq+iAJ43bWwFOjMfd9OSQYjLMAptOkEvRgCfQbUS
hh7ue8U9MMp3ME73lHwf0I0=
=acqz
-----END PGP SIGNATURE-----

--nextPart1208871.ufsJEfDTOy--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711241525.10171.c47g>