diff --git a/launcher/Assert.h b/launcher/Assert.h new file mode 100644 index 000000000..df15ed389 --- /dev/null +++ b/launcher/Assert.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2025 Octol1ttle + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#if !defined(ASSERT_NEVER) +#define ASSERT_NEVER(cond) (Q_ASSERT(cond == false), cond) +#endif diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index b89a49186..1ecea9d1d 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -102,6 +102,9 @@ set(CORE_SOURCES MMCTime.cpp MTPixmapCache.h + + # Assertion helper + Assert.h ) if (UNIX AND NOT CYGWIN AND NOT APPLE) set(CORE_SOURCES @@ -1614,7 +1617,7 @@ if(WIN32 OR (UNIX AND APPLE)) ) # FIXME: remove this crap once we stop using msys2 if(MINGW) - # i've not found a solution better than injecting the config vars like this... + # i've not found a solution better than injecting the config vars like this... # with install(CODE" for everything everything just breaks install(CODE " set(QT_PLUGINS_DIR \"${QT_PLUGINS_DIR}\") @@ -1622,7 +1625,7 @@ if(WIN32 OR (UNIX AND APPLE)) set(QT_LIBEXECS_DIR \"${QT_LIBEXECS_DIR}\") set(CMAKE_SYSTEM_LIBRARY_PATH \"${CMAKE_SYSTEM_LIBRARY_PATH}\") set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\") - " + " COMPONENT bundle) install(CODE [[ diff --git a/launcher/tasks/Task.cpp b/launcher/tasks/Task.cpp index d59660146..3032521c8 100644 --- a/launcher/tasks/Task.cpp +++ b/launcher/tasks/Task.cpp @@ -38,6 +38,8 @@ #include +#include "Assert.h" + Q_LOGGING_CATEGORY(taskLogC, "launcher.task") Task::Task(bool show_debug) : m_show_debug(show_debug) @@ -96,9 +98,8 @@ void Task::start() break; } case State::Running: { - if (m_show_debug) + if (ASSERT_NEVER(isRunning()) && m_show_debug) qCWarning(taskLogC) << "The launcher tried to start task" << describe() << "while it was already running!"; - Q_ASSERT(!isRunning()); return; } } @@ -111,9 +112,8 @@ void Task::start() void Task::emitFailed(QString reason) { // Don't fail twice. - if (!isRunning()) { + if (ASSERT_NEVER(!isRunning())) { qCCritical(taskLogC) << "Task" << describe() << "failed while not running!!!!: " << reason; - Q_ASSERT(!isRunning()); return; } m_state = State::Failed; @@ -126,9 +126,8 @@ void Task::emitFailed(QString reason) void Task::emitAborted() { // Don't abort twice. - if (!isRunning()) { + if (ASSERT_NEVER(!isRunning())) { qCCritical(taskLogC) << "Task" << describe() << "aborted while not running!!!!"; - Q_ASSERT(!isRunning()); return; } m_state = State::AbortedByUser; @@ -142,9 +141,8 @@ void Task::emitAborted() void Task::emitSucceeded() { // Don't succeed twice. - if (!isRunning()) { + if (ASSERT_NEVER(!isRunning())) { qCCritical(taskLogC) << "Task" << describe() << "succeeded while not running!!!!"; - Q_ASSERT(!isRunning()); return; } m_state = State::Succeeded;