Skip to content

Commit

Permalink
Exit with an error message if BASS_Init fails
Browse files Browse the repository at this point in the history
This resolves #27
  • Loading branch information
DeinAlptraum committed Jun 30, 2024
1 parent 2e54a0c commit f3dbda1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/QUMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ QUMainWindow::QUMainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::QUM
lyricsProgressBar->setFormat("%v/%m (%p%)");
QMainWindow::statusBar()->addPermanentWidget(lyricsProgressBar, 1);

if (BASS_Init(-1, 44100, 0, 0, NULL)) {
QMainWindow::statusBar()->showMessage(tr("BASS initialized."));
}

QSettings settings;
bool firstRun = settings.value("firstRun", "true").toBool();

Expand Down
18 changes: 18 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//#include <QRandomGenerator>

void initApplication();
void initBASS();
void initLanguage(QApplication&, QTranslator&, QTranslator&, QSplashScreen&);
void handlePreviousAppCrash();
void handleWipWarning();
Expand Down Expand Up @@ -49,6 +50,7 @@ int main(int argc, char *argv[]) {
handleArguments();

QUMainWindow mainWindow;
initBASS();
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

mainWindow.show();
Expand All @@ -70,6 +72,22 @@ void initApplication() {
QCoreApplication::setApplicationName("UltraStar Creator");
}

void initBASS()
{
if (!BASS_Init(-1, 44100, 0, 0, NULL))
{
QPushButton *quitButton = new QPushButton();
QMessageBox dlg;
dlg.setWindowTitle("BASS could not be initialized");
dlg.setText("BASS audio library could not initialize the audio device.\nThe application will quit now.");
dlg.setDefaultButton(quitButton);
dlg.setIcon(QMessageBox::Critical);

QObject::connect(&dlg, &QMessageBox::accepted, qApp, &QCoreApplication::quit, Qt::QueuedConnection);
dlg.exec();
}
}

/*!
* Installs a proper translator according to the registry settings. That's why you
* have to restart this application if you want to change its language. Uses the system
Expand Down

0 comments on commit f3dbda1

Please sign in to comment.