Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init GX2 to reduce screen corruption if no menu was shown #38

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bool writeFileContent(const std::string &path, const std::string &content) {
extern "C" void __fini();
extern "C" void __init_wut_malloc();
void LoadAndRunModule(std::string_view filepath, std::string_view environment_path);
void ClearSavedFrameBuffers();

int main(int argc, char **argv) {
// We need to call __init_wut_malloc somewhere so wut_malloc will be used for the memory allocation.
Expand Down Expand Up @@ -128,6 +129,7 @@ int main(int argc, char **argv) {
}

bool noEnvironmentsFound = false;
bool shownMenu = false;

std::string environmentPath = std::string(environmentPathFromIOSU);
if (!environmentPath.starts_with("fs:/vol/external01/wiiu/environments/")) { // If the environment path in IOSU is empty or unexpected, read config
Expand Down Expand Up @@ -163,16 +165,32 @@ int main(int argc, char **argv) {
InputUtils::InputData input = InputUtils::getControllerInput();

if (forceMenu || ((input.trigger | input.hold) & VPAD_BUTTON_X) == VPAD_BUTTON_X) {
shownMenu = true;
DEBUG_FUNCTION_LINE_VERBOSE("Open menu!");
environmentPath = EnvironmentSelectionScreen(environmentPaths, autobootIndex);
if (environmentPaths.empty()) {
noEnvironmentsFound = true;
} else {
DEBUG_FUNCTION_LINE_VERBOSE("Selected %s", environmentPath.c_str());
}
} else {
}
InputUtils::DeInit();
}

if (!shownMenu) {
// Clear saved frame buffer to reduce screen corruption
ClearSavedFrameBuffers();

OSScreenInit();

// Call GX2Init to shut down OSScreen
GX2Init(nullptr);

GX2SetTVEnable(FALSE);
GX2SetDRCEnable(FALSE);
}

RevertMainHook();

if (!noEnvironmentsFound) {
Expand Down