Page 1 of 1

2nd libvlc_destroy() call is crashing

Posted: 09 Jan 2009 15:04
by g6r6e6g
Hello,

I try to play 2 videos on vlc086e (win32 libvlc) with vmem plugin,
I create new instance/play 1st video => OK
I createnew instance/play 2nd video => OK
I stop and destroy correctly my 1st instance,
but libvlc_destroy() crash on my 2nd instance.
If I create/destroy 2 videos sequentially, no problem !

Any idea ?
Thank you

I m using those args :

Code: Select all

"--no-one-instance", "--loop", "--no-stats", "--intf", "dummy", "--fast-mutex", "--win9x-cv-method=1", "--plugin-path=.\\VLCplugins", "--vout", "vmem", "--vmem-width", pwidth, "--vmem-height", pheight, "--vmem-pitch", ppitch, "--vmem-chroma", "RV16", "--vmem-lock", plock, "--vmem-unlock", punlock, "--vmem-data", pdata,

Re: 2nd libvlc_destroy() call is crashing

Posted: 09 Jan 2009 15:53
by erwan10
beware of multiple instances of libvlc ! They are not independent.

A new libvlc instance overwrites options passed to a previous one. In the case of vmem, some of these options are pointers to functions So you can very easily end up with a crash.

Re: 2nd libvlc_destroy() call is crashing

Posted: 09 Jan 2009 16:55
by g6r6e6g
Thank you erwan10 for your response,

If I understand there is 1 risk when using config_GetPsz()
but config_GetPsz() is only called in Init() of vmem and args are copied into
instance datas ...
so I do not see the impact on libvlc_destroy().

vmem source code part :

Code: Select all

struct vout_sys_t { int i_width, i_height, i_pitch; void * (*pf_lock) (void *); void (*pf_unlock) (void *); void *p_data; }; static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = ( vout_thread_t * )p_this; /* Allocate instance and initialize some members */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); . . . static int Init( vout_thread_t *p_vout ) { . . . psz_tmp = config_GetPsz( p_vout, "vmem-lock" ); p_vout->p_sys->pf_lock = (void * (*) (void *))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); . . . static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = ( vout_thread_t * )p_this; /* Destroy structure */ free( p_vout->p_sys ); }

I tried the same test without using vmem and I found an interesting think :
when I compile/link on cygwin => OK
when I compile/link with VisualStudio2005 => libvlc_destroy() crashes on 2nd call


After some investigations, I found crash in 2nd call to libvlc_destroy() occurs in VLCsources/misc/messages.c

Code: Select all

void __msg_Destroy( vlc_object_t *p_this ) { int i; for( i = p_this->p_libvlc->msg_bank.i_queues -1 ; i >= 0; i-- ) { ... } vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) ); <= this lock in libvlc context is maybe already freed !! }

Re: 2nd libvlc_destroy() call is crashing

Posted: 12 Jan 2009 11:43
by g6r6e6g
In libvlc.c, we only create the Msg queue on 1st call to VLC_Create(), but when calling VLC_Destroy() we systematically destroy the Msg queue, can someone confirm there is 1 bug here ?

Code: Select all

int VLC_Create( void ) { ... if( !libvlc.b_ready ) { ... /* Initialize message queue */ msg_Create( p_libvlc ); ... libvlc.b_ready = VLC_TRUE; } int VLC_Destroy( int i_object ) { ... /* * System specific cleaning code */ system_End( p_vlc ); /* * Free message queue. * Nobody shall use msg_* afterward. */ msg_Flush( p_vlc ); msg_Destroy( p_libvlc ); ... }
Sorry for this double-post, just want some expert help ;-)
Thank you