sysclk: fix crash issues

This commit is contained in:
souldbminersmwc
2025-12-25 19:01:43 -05:00
parent 329feea148
commit 64e079dbdb
4 changed files with 25 additions and 33 deletions

View File

@@ -13,63 +13,57 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "info_gui.h" #include "info_gui.h"
#include "../format.h" #include "../format.h"
#include <tesla.hpp> #include <tesla.hpp>
#include <string> #include <string>
tsl::elm::ListItem* cpuSpeedoItem;
tsl::elm::ListItem* gpuSpeedoItem;
tsl::elm::ListItem* socSpeedoItem;
InfoGui::InfoGui() InfoGui::InfoGui()
{ {
if (!this->Currentcontext) [[unlikely]] { // Initialize display strings
this->Currentcontext = new SysClkContext; memset(speedoStrings, 0, sizeof(speedoStrings));
}
Result rc = sysclkIpcGetCurrentContext(this->Currentcontext);
if (R_FAILED(rc)) [[unlikely]] {
FatalGui::openWithResultCode("sysclkIpcGetCurrentContext", rc);
return;
}
} }
InfoGui::~InfoGui() InfoGui::~InfoGui()
{ {
} }
void InfoGui::listUI() void InfoGui::listUI()
{ {
tsl::elm::ListItem* cpuSpeedoItem = cpuSpeedoItem =
new tsl::elm::ListItem("CPU Speedo"); new tsl::elm::ListItem("CPU Speedo");
cpuSpeedoItem->setValue(std::to_string(this->Currentcontext->speedos[HorizonOCSpeedo_CPU]));
this->listElement->addItem(cpuSpeedoItem); this->listElement->addItem(cpuSpeedoItem);
tsl::elm::ListItem* gpuSpeedoItem = gpuSpeedoItem =
new tsl::elm::ListItem("GPU Speedo"); new tsl::elm::ListItem("GPU Speedo");
gpuSpeedoItem->setValue(std::to_string(this->Currentcontext->speedos[HorizonOCSpeedo_GPU]));
this->listElement->addItem(gpuSpeedoItem); this->listElement->addItem(gpuSpeedoItem);
tsl::elm::ListItem* socSpeedoItem = socSpeedoItem =
new tsl::elm::ListItem("GPU Speedo"); new tsl::elm::ListItem("SOC Speedo");
socSpeedoItem->setValue(std::to_string(this->Currentcontext->speedos[HorizonOCSpeedo_SOC]));
this->listElement->addItem(socSpeedoItem); this->listElement->addItem(socSpeedoItem);
} }
void InfoGui::update() void InfoGui::update()
{ {
BaseMenuGui::update(); BaseMenuGui::update();
} }
void InfoGui::refresh() void InfoGui::refresh()
{ {
BaseMenuGui::refresh(); BaseMenuGui::refresh();
static int frameCounter = 0; if (!this->context)
return;
if (this->context && ++frameCounter >= 60) { // Format speedo strings once per refresh
frameCounter = 0; sprintf(speedoStrings[0], "%u", this->context->speedos[HorizonOCSpeedo_CPU]);
sprintf(speedoStrings[1], "%u", this->context->speedos[HorizonOCSpeedo_GPU]);
sprintf(speedoStrings[2], "%u", this->context->speedos[HorizonOCSpeedo_SOC]);
cpuSpeedoItem->setValue(speedoStrings[HorizonOCSpeedo_CPU]); // this is SO hacky but it works i guess
gpuSpeedoItem->setValue(speedoStrings[HorizonOCSpeedo_GPU]);
socSpeedoItem->setValue(speedoStrings[HorizonOCSpeedo_SOC]);
}
} }

View File

@@ -13,7 +13,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include "../../ipc.h" #include "../../ipc.h"
#include "base_menu_gui.h" #include "base_menu_gui.h"
@@ -26,7 +25,8 @@
class InfoGui : public BaseMenuGui class InfoGui : public BaseMenuGui
{ {
protected: protected:
SysClkContext* Currentcontext; char speedoStrings[3][16]; // Pre-formatted speedo strings
public: public:
InfoGui(); InfoGui();
~InfoGui(); ~InfoGui();
@@ -34,5 +34,4 @@ public:
void listUI() override; void listUI() override;
void update() override; void update() override;
void refresh() override; void refresh() override;
}; };

View File

@@ -74,7 +74,7 @@ void MainGui::listUI()
tsl::elm::ListItem* globalOverrideItem = new tsl::elm::ListItem("Temporary Overrides"); tsl::elm::ListItem* globalOverrideItem = new tsl::elm::ListItem("Temporary Overrides");
globalOverrideItem->setClickListener([this](u64 keys) { globalOverrideItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A) if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{ {
tsl::changeTo<GlobalOverrideGui>(); tsl::changeTo<GlobalOverrideGui>();
return true; return true;
@@ -100,7 +100,7 @@ void MainGui::listUI()
tsl::elm::ListItem* infoItem = new tsl::elm::ListItem("Information"); tsl::elm::ListItem* infoItem = new tsl::elm::ListItem("Information");
infoItem->setClickListener([this](u64 keys) { infoItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A) if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{ {
tsl::changeTo<InfoGui>(); tsl::changeTo<InfoGui>();
return true; return true;

View File

@@ -32,7 +32,6 @@
class MainGui : public BaseMenuGui class MainGui : public BaseMenuGui
{ {
protected: protected:
SysClkContext* context;
tsl::elm::ToggleListItem* enabledToggle; tsl::elm::ToggleListItem* enabledToggle;
public: public: