Skip to content

Commit

Permalink
macos: don't assume that all macOS major versions are simple numeric …
Browse files Browse the repository at this point in the history
…values (#3836)

Related to open-goal/launcher#664
Likely Fixes open-goal/launcher#663
  • Loading branch information
xTVaser authored Jan 11, 2025
1 parent 434484e commit f6fad06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions common/util/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/common_types.h"
#include "common/log/log.h"
#include "common/util/string_util.h"

#ifdef __APPLE__
#include <stdio.h>
Expand Down Expand Up @@ -112,7 +113,7 @@ CpuInfo& get_cpu_info() {
return gCpuInfo;
}

std::optional<double> get_macos_version() {
std::optional<double> get_macos_major_version() {
#ifndef __APPLE__
return {};
#else
Expand All @@ -124,7 +125,11 @@ std::optional<double> get_macos_version() {
return {};
}
try {
return std::stod(buffer);
std::string macos_major_version = buffer;
if (str_util::contains(buffer, ".")) {
macos_major_version = str_util::split_string(macos_major_version, ".")[0];
}
return std::stod(macos_major_version);
} catch (std::exception& e) {
lg::error("Error occured when attempting to convert sysctl value {} to number", buffer);
return {};
Expand Down
2 changes: 1 addition & 1 deletion common/util/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ struct CpuInfo {

CpuInfo& get_cpu_info();

std::optional<double> get_macos_version();
std::optional<double> get_macos_major_version();
4 changes: 2 additions & 2 deletions game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ int main(int argc, char** argv) {
// Check if we are on a modern enough version of macOS so that AVX can be
// emulated via rosetta
#ifdef __APPLE__
auto macos_version = get_macos_version();
if (macos_version < 15.0) {
auto macos_major_version = get_macos_major_version();
if (macos_major_version < 15.0) {
lg::info(
"Your CPU does not support AVX. But the newer version of Rosetta supports it, update to "
"atleast Sequoia to run OpenGOAL!");
Expand Down

0 comments on commit f6fad06

Please sign in to comment.