Skip to content

Commit

Permalink
Initializes panic handler for Slint (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Nov 26, 2024
1 parent c0ff3b9 commit d249ecf
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 399 deletions.
1 change: 0 additions & 1 deletion gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
app_data.cpp
cpu_settings.cpp
display_settings.cpp
game_models.cpp
initialize_wizard.cpp
launch_settings.cpp
main.cpp
Expand Down
3 changes: 0 additions & 3 deletions gui/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ struct RustError;
extern "C" {
#endif // __cplusplus

void set_panic_hook(void *cx,
void (*hook)(const char*, size_t, uint32_t, const char*, size_t, void*));

void error_free(struct RustError *e);

const char *error_message(const struct RustError *e);
Expand Down
138 changes: 0 additions & 138 deletions gui/game_models.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions gui/game_models.hpp

This file was deleted.

45 changes: 5 additions & 40 deletions gui/launch_settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "launch_settings.hpp"
#include "cpu_settings.hpp"
#include "display_settings.hpp"
#include "game_models.hpp"
#include "profile_models.hpp"
#include "resources.hpp"

Expand All @@ -20,11 +19,10 @@
#include <utility>

#ifdef __APPLE__
LaunchSettings::LaunchSettings(ProfileList *profiles, GameListModel *games, QWidget *parent) :
LaunchSettings::LaunchSettings(ProfileList *profiles, QWidget *parent) :
#else
LaunchSettings::LaunchSettings(
ProfileList *profiles,
GameListModel *games,
QList<VkPhysicalDevice> &&vkDevices,
QWidget *parent) :
#endif
Expand All @@ -37,9 +35,9 @@ LaunchSettings::LaunchSettings(
auto layout = new QVBoxLayout();

#ifdef __APPLE__
layout->addWidget(buildSettings(games));
layout->addWidget(buildSettings());
#else
layout->addWidget(buildSettings(games, std::move(vkDevices)));
layout->addWidget(buildSettings(std::move(vkDevices)));
#endif
layout->addLayout(buildActions(profiles));

Expand Down Expand Up @@ -73,9 +71,9 @@ DisplayDevice *LaunchSettings::currentDisplayDevice() const
#endif

#ifdef __APPLE__
QWidget *LaunchSettings::buildSettings(GameListModel *games)
QWidget *LaunchSettings::buildSettings()
#else
QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDevice> &&vkDevices)
QWidget *LaunchSettings::buildSettings(QList<VkPhysicalDevice> &&vkDevices)
#endif
{
// Tab.
Expand Down Expand Up @@ -105,14 +103,11 @@ QWidget *LaunchSettings::buildSettings(GameListModel *games, QList<VkPhysicalDev
m_games->setContextMenuPolicy(Qt::CustomContextMenu);
m_games->setSortingEnabled(true);
m_games->setWordWrap(false);
m_games->setModel(games);
m_games->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
m_games->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
m_games->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
m_games->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

connect(m_games, &QWidget::customContextMenuRequested, this, &LaunchSettings::requestGamesContextMenu);

tab->addTab(m_games, loadIcon(":/resources/view-comfy.svg", iconSize), "Games");

return tab;
Expand Down Expand Up @@ -164,36 +159,6 @@ QLayout *LaunchSettings::buildActions(ProfileList *profiles)
return layout;
}

void LaunchSettings::requestGamesContextMenu(const QPoint &pos)
{
// Get item index.
auto index = m_games->indexAt(pos);

if (!index.isValid()) {
return;
}

auto model = reinterpret_cast<GameListModel *>(m_games->model());
auto game = model->get(index.row());

// Setup menu.
QMenu menu(this);
QAction openFolder("Open &Folder", this);

menu.addAction(&openFolder);

// Show menu.
auto selected = menu.exec(m_games->viewport()->mapToGlobal(pos));

if (!selected) {
return;
}

if (selected == &openFolder) {
QDesktopServices::openUrl(QUrl::fromLocalFile(game->directory()));
}
}

void LaunchSettings::profileChanged(int index)
{
assert(index >= 0);
Expand Down
8 changes: 3 additions & 5 deletions gui/launch_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ class LaunchSettings final : public QWidget {
Q_OBJECT
public:
#ifdef __APPLE__
LaunchSettings(ProfileList *profiles, GameListModel *games, QWidget *parent = nullptr);
LaunchSettings(ProfileList *profiles, QWidget *parent = nullptr);
#else
LaunchSettings(
ProfileList *profiles,
GameListModel *games,
QList<VkPhysicalDevice> &&vkDevices,
QWidget *parent = nullptr);
#endif
Expand All @@ -42,13 +41,12 @@ class LaunchSettings final : public QWidget {
void startClicked(const QString &debugAddr);
private:
#ifdef __APPLE__
QWidget *buildSettings(GameListModel *games);
QWidget *buildSettings();
#else
QWidget *buildSettings(GameListModel *games, QList<VkPhysicalDevice> &&vkDevices);
QWidget *buildSettings(QList<VkPhysicalDevice> &&vkDevices);
#endif
QLayout *buildActions(ProfileList *profiles);

void requestGamesContextMenu(const QPoint &pos);
void profileChanged(int index);

DisplaySettings *m_display;
Expand Down
28 changes: 0 additions & 28 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,6 @@
#include <sys/resource.h>
#endif

static void panicHook(
const char *file,
size_t flen,
uint32_t line,
const char *msg,
size_t mlen,
void *cx)
{
auto main = reinterpret_cast<QObject *>(cx);
auto type = QThread::currentThread() == main->thread()
? Qt::DirectConnection
: Qt::BlockingQueuedConnection;

QMetaObject::invokeMethod(main, [=]() {
auto text = QString("An unexpected error occurred at %1:%2: %3")
.arg(QString::fromUtf8(file, flen))
.arg(line)
.arg(QString::fromUtf8(msg, mlen));

QMessageBox::critical(nullptr, "Fatal Error", text);
}, type);
}

int main(int argc, char *argv[])
{
// Setup application.
Expand All @@ -67,11 +44,6 @@ int main(int argc, char *argv[])
args.addOption(Args::kernel);
args.process(app);

// Hook Rust panic.
QObject panic;

set_panic_hook(&panic, panicHook);

// Initialize Vulkan.
#ifndef __APPLE__
QVulkanInstance vulkan;
Expand Down
7 changes: 2 additions & 5 deletions gui/main_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "main_window.hpp"
#include "app_data.hpp"
#include "game_models.hpp"
#include "launch_settings.hpp"
#include "path.hpp"
#include "profile_models.hpp"
Expand Down Expand Up @@ -51,7 +50,6 @@ MainWindow::MainWindow(
m_args(args),
m_main(nullptr),
m_profiles(nullptr),
m_games(nullptr),
m_launch(nullptr),
m_screen(nullptr),
m_debugNoti(nullptr)
Expand Down Expand Up @@ -92,11 +90,10 @@ MainWindow::MainWindow(

// Launch settings.
m_profiles = new ProfileList(this);
m_games = new GameListModel(this);
#ifdef __APPLE__
m_launch = new LaunchSettings(m_profiles, m_games);
m_launch = new LaunchSettings(m_profiles);
#else
m_launch = new LaunchSettings(m_profiles, m_games, std::move(vkDevices));
m_launch = new LaunchSettings(m_profiles, std::move(vkDevices));
#endif

connect(m_launch, &LaunchSettings::saveClicked, this, &MainWindow::saveProfile);
Expand Down
Loading

0 comments on commit d249ecf

Please sign in to comment.