From e40a6bc627d43c6c148ce73d9c80e2a8900fe569 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sat, 4 Feb 2017 19:04:13 +0100 Subject: [PATCH] Avoid crash on gui when rendering from command line and no write access (#3322) --- src/core/audio/AudioFileDevice.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/audio/AudioFileDevice.cpp b/src/core/audio/AudioFileDevice.cpp index b04cc4ebdcc..c4fd72fc2b4 100644 --- a/src/core/audio/AudioFileDevice.cpp +++ b/src/core/audio/AudioFileDevice.cpp @@ -27,6 +27,7 @@ #include "AudioFileDevice.h" #include "ExportProjectDialog.h" +#include "GuiApplication.h" AudioFileDevice::AudioFileDevice( const sample_rate_t _sample_rate, @@ -50,17 +51,27 @@ AudioFileDevice::AudioFileDevice( const sample_rate_t _sample_rate, if( m_outputFile.open( QFile::WriteOnly | QFile::Truncate ) == false ) { - QMessageBox::critical( NULL, - ExportProjectDialog::tr( "Could not open file" ), - ExportProjectDialog::tr( "Could not open file %1 " + QString title, message; + title = ExportProjectDialog::tr( "Could not open file" ); + message = ExportProjectDialog::tr( "Could not open file %1 " "for writing.\nPlease make " - "sure you have write-" + "sure you have write " "permission to the file and " "the directory containing the " - "file and try again!" ).arg( - _file ), - QMessageBox::Ok, - QMessageBox::NoButton ); + "file and try again!" + ).arg( _file ); + + if( gui ) + { + QMessageBox::critical( NULL, title, message, + QMessageBox::Ok, + QMessageBox::NoButton ); + } + else + { + fprintf( stderr, "%s\n", message.toUtf8().constData() ); + exit( EXIT_FAILURE ); + } } }