Commit 0a99e452 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Ensure we are not wrapping a null libvlc_media_t

parent 43cab792
......@@ -724,7 +724,7 @@ class MediaListEventManager : public EventManager
{
auto callback = static_cast<DecayPtr<Func>>( data );
auto media = e->u.media_list_will_add_item.item;
(*callback)(media != nullptr ? std::make_shared<Media>( media, true ) : nullptr,
(*callback)( media != nullptr ? std::make_shared<Media>( media, true ) : nullptr,
e->u.media_list_will_add_item.index );
});
}
......
......@@ -363,6 +363,11 @@ public:
Media duplicate()
{
auto obj = libvlc_media_duplicate(*this);
// Assume failure to duplicate is due to VLC_ENOMEM.
// libvlc_media_duplicate(nullptr) would also return nullptr, but
// we consider the use of an empty libvlcpp instance undefined.
if ( obj == nullptr )
throw std::bad_alloc();
return Media( obj, false );
}
......
......@@ -171,6 +171,8 @@ public:
MediaPtr itemAtIndex(int i_pos)
{
auto ptr = libvlc_media_list_item_at_index(*this,i_pos);
if ( ptr == nullptr )
return nullptr;
return std::make_shared<Media>( ptr, false );
}
......
......@@ -124,7 +124,9 @@ public:
*/
MediaPtr media()
{
libvlc_media_t* media = libvlc_media_player_get_media(*this);
auto media = libvlc_media_player_get_media(*this);
if ( media == nullptr )
return nullptr;
return std::make_shared<Media>( media, true );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment