Skip to content

Commit

Permalink
Show warning for x32 game on x64 os
Browse files Browse the repository at this point in the history
  • Loading branch information
olanti-p authored Sep 13, 2023
1 parent 9b5a979 commit cf551a3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
56 changes: 51 additions & 5 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,16 +1728,28 @@ std::string game_info::operating_system_version()
#endif
}

std::string game_info::bitness()
std::optional<int> game_info::bitness()
{
if( sizeof( void * ) == 8 ) {
return "64-bit";
return 64;
}

if( sizeof( void * ) == 4 ) {
return "32-bit";
return 32;
}

return std::nullopt;
}

std::string game_info::bitness_string()
{
auto b = bitness();
if( b && *b == 32 ) {
return "32-bit";
}
if( b && *b == 64 ) {
return "64-bit";
}
return "Unknown";
}

Expand Down Expand Up @@ -1799,7 +1811,7 @@ std::string game_info::game_report()
report <<
"- OS: " << operating_system() << "\n" <<
" - OS Version: " << os_version << "\n" <<
"- Game Version: " << game_version() << " [" << bitness() << "]\n" <<
"- Game Version: " << game_version() << " [" << bitness_string() << "]\n" <<
"- Graphics Version: " << graphics_version() << "\n" <<
"- LAPI Version: " << cata::get_lapi_version_string() << "\n" <<
"- Game Language: " << lang_translated << " [" << lang << "]\n" <<
Expand All @@ -1808,4 +1820,38 @@ std::string game_info::game_report()
return report.str();
}

// vim:tw=72:sw=4:fdm=marker:fdl=0:
std::optional<int> get_os_bitness()
{
#if defined(_WIN32)
SYSTEM_INFO si;
GetNativeSystemInfo( &si );
switch( si.wProcessorArchitecture ) {
case PROCESSOR_ARCHITECTURE_AMD64:
return 64;

case PROCESSOR_ARCHITECTURE_INTEL:
return 32;

default:
// FIXME: other architectures?
break;
}
#elif defined(__linux__)
std::string output;
output = shell_exec( "getconf LONG_BIT" );

if( !output.empty() ) {
// remove trailing '\n', if any.
output.erase( std::remove( output.begin(), output.end(), '\n' ),
output.end() );
}

if( output == "64" ) {
return 64;
} else if( output == "32" ) {
return 32;
}
#endif
// FIXME: osx, android
return std::nullopt;
}
13 changes: 11 additions & 2 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// Includes {{{1
// ---------------------------------------------------------------------
#include <iostream>
#include <optional>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -110,9 +111,12 @@ std::string operating_system();
/** Return a detailed version of the operating system; e.g. "Ubuntu 18.04" or "(Windows) 10 1809".
*/
std::string operating_system_version();
/** Return the "bitness" of the game (not necessarily of the operating system); either: 64-bit, 32-bit or Unknown.
/** Return the "bitness" of the game (not necessarily of the operating system); either: 64, 32 or nullopt.
*/
std::string bitness();
std::optional<int> bitness();
/** Return the "bitness" string of the game (not necessarily of the operating system); either: 64-bit, 32-bit or Unknown.
*/
std::string bitness_string();
/** Return the game version, as in the entry screen.
*/
std::string game_version();
Expand Down Expand Up @@ -240,6 +244,11 @@ std::string capture_debugmsg_during( const std::function<void()> &func );
*/
void replay_buffered_debugmsg_prompts();

/**
* Retrieves OS bitness (32, 64 or nullopt if detection failed)
*/
std::optional<int> get_os_bitness();

// Debug Only {{{1
// ---------------------------------------------------------------------

Expand Down
15 changes: 15 additions & 0 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,21 @@ bool main_menu::opening_screen()
return false;
}

std::optional<int> os_bitness = get_os_bitness();
std::optional<int> game_bitness = game_info::bitness();
if( os_bitness && *os_bitness == 64 && game_bitness && *game_bitness == 32 ) {
popup( _(
"You are running x32 build of the game on a x64 operating system. "
"This means the game will NOT be able to access all memory, "
"and you may experience random out-of-memory crashes. "
"Consider obtaining a x64 build of the game to avoid that, "
"but if you *really* want to be running x32 build of the game "
"for some reason (or don't have a choice), you may want to lower "
"your memory usage by disabling tileset, soundpack and mods "
"and increasing autosave frequency."
) );
}

load_char_templates();

ctxt.register_cardinal();
Expand Down

0 comments on commit cf551a3

Please sign in to comment.