From da9208969d2299ee44d8692380680cae47dd07c6 Mon Sep 17 00:00:00 2001 From: pingkai Date: Tue, 21 Jan 2020 17:08:34 +0800 Subject: [PATCH] fix(cicadaPlayer): fix on error crash in travis env Signed-off-by: pingkai --- cmdline/cicadaPlayer.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmdline/cicadaPlayer.cpp b/cmdline/cicadaPlayer.cpp index ae5b863f2..814d084c9 100644 --- a/cmdline/cicadaPlayer.cpp +++ b/cmdline/cicadaPlayer.cpp @@ -20,6 +20,7 @@ using IEvent = IEventReceiver::IEvent; struct cicadaCont { MediaPlayer *player; IEventReceiver *receiver; + bool error; }; static void onVideoSize(int64_t width, int64_t height, void *userData) @@ -36,7 +37,8 @@ static void onEOS(void *userData) { auto *cont = static_cast(userData); auto *event = new IEvent(IEvent::TYPE_EXIT); - cont->receiver->push(std::unique_ptr(event)); + if (cont->receiver) + cont->receiver->push(std::unique_ptr(event)); } static void onEvent(int64_t errorCode, const void *errorMsg, void *userData) @@ -64,9 +66,12 @@ static void onError(int64_t errorCode, const void *errorMsg, void *userData) if (errorMsg) { AF_LOGE("%s\n", errorMsg); } - - auto *event = new IEvent(IEvent::TYPE_EXIT); - cont->receiver->push(std::unique_ptr(event)); + if (cont->receiver) { + auto *event = new IEvent(IEvent::TYPE_EXIT); + cont->receiver->push(std::unique_ptr(event)); + } else{ + cont->error= true; + } } int main(int argc, const char **argv) @@ -106,7 +111,7 @@ int main(int argc, const char **argv) player->Prepare(); bool quite = false; - while (!quite) { + while (!quite && !cicada.error) { #ifdef ENABLE_SDL receiver.poll(quite); #endif