fix crash on fallback

This commit is contained in:
Glenn Maynard
2004-02-25 05:26:20 +00:00
parent 0c1ef3f594
commit c69f29e54d
@@ -577,31 +577,42 @@ void MovieTexture_FFMpeg::CreateDecoder()
if ( ret < 0 ) if ( ret < 0 )
RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", GetID().filename.c_str()) ); RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", GetID().filename.c_str()) );
decoder->m_stream = FindVideoStream( decoder->m_fctx ); avcodec::AVStream *stream = FindVideoStream( decoder->m_fctx );
if ( decoder->m_stream == NULL ) if ( stream == NULL )
RageException::Throw( "AVCodec (%s): Couldn't find any video streams", GetID().filename.c_str() ); RageException::Throw( "AVCodec (%s): Couldn't find any video streams", GetID().filename.c_str() );
if( decoder->m_stream->codec.codec_id == avcodec::CODEC_ID_NONE ) if( stream->codec.codec_id == avcodec::CODEC_ID_NONE )
RageException::ThrowNonfatal( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), decoder->m_stream->codec.codec_tag ); RageException::ThrowNonfatal( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), stream->codec.codec_tag );
avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( decoder->m_stream->codec.codec_id ); avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( stream->codec.codec_id );
if( codec == NULL ) if( codec == NULL )
RageException::Throw( "AVCodec (%s): Couldn't find decoder %i", GetID().filename.c_str(), decoder->m_stream->codec.codec_id ); RageException::Throw( "AVCodec (%s): Couldn't find decoder %i", GetID().filename.c_str(), stream->codec.codec_id );
LOG->Trace("Opening codec %s", codec->name ); LOG->Trace("Opening codec %s", codec->name );
ret = avcodec::avcodec_open( &decoder->m_stream->codec, codec ); ret = avcodec::avcodec_open( &stream->codec, codec );
if ( ret < 0 ) if ( ret < 0 )
RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", GetID().filename.c_str(), codec->name) ); RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", GetID().filename.c_str(), codec->name) );
/* Don't set this until we successfully open stream->codec, so we don't try to close it
* on an exception unless it was really opened. */
decoder->m_stream = stream;
} }
/* Delete the decoder. The decoding thread must be stopped. */ /* Delete the decoder. The decoding thread must be stopped. */
void MovieTexture_FFMpeg::DestroyDecoder() void MovieTexture_FFMpeg::DestroyDecoder()
{ {
avcodec::avcodec_close( &decoder->m_stream->codec ); if( decoder->m_stream )
avcodec::av_close_input_file( decoder->m_fctx ); {
decoder->m_fctx = NULL; avcodec::avcodec_close( &decoder->m_stream->codec );
decoder->m_stream = NULL; decoder->m_stream = NULL;
}
if( decoder->m_fctx )
{
avcodec::av_close_input_file( decoder->m_fctx );
decoder->m_fctx = NULL;
}
} }
/* Delete the surface and texture. The decoding thread must be stopped, and this /* Delete the surface and texture. The decoding thread must be stopped, and this