diff options
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/SCsub | 7 | ||||
-rw-r--r-- | platform/osx/audio_driver_osx.cpp | 11 | ||||
-rw-r--r-- | platform/osx/crash_handler_osx.h | 47 | ||||
-rw-r--r-- | platform/osx/crash_handler_osx.mm | 178 | ||||
-rw-r--r-- | platform/osx/dir_access_osx.h | 3 | ||||
-rw-r--r-- | platform/osx/dir_access_osx.mm | 18 | ||||
-rw-r--r-- | platform/osx/export/export.cpp | 15 | ||||
-rw-r--r-- | platform/osx/godot_main_osx.mm | 8 | ||||
-rw-r--r-- | platform/osx/os_osx.h | 9 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 30 | ||||
-rw-r--r-- | platform/osx/power_osx.cpp | 16 | ||||
-rw-r--r-- | platform/osx/power_osx.h | 6 |
12 files changed, 319 insertions, 29 deletions
diff --git a/platform/osx/SCsub b/platform/osx/SCsub index 27117c2e8d..5b2de54535 100644 --- a/platform/osx/SCsub +++ b/platform/osx/SCsub @@ -3,6 +3,7 @@ Import('env') files = [ + 'crash_handler_osx.mm', 'os_osx.mm', 'godot_main_osx.mm', 'audio_driver_osx.cpp', @@ -12,4 +13,8 @@ files = [ 'power_osx.cpp', ] -env.Program('#bin/godot', files) +prog = env.Program('#bin/godot', files) +if (env['target'] == "debug" or env['target'] == "release_debug"): + # Build the .dSYM file for atos + action = "dsymutil " + File(prog)[0].path + " -o " + File(prog)[0].path + ".dSYM" + env.AddPostAction(prog, action) diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp index 78c52af201..3b3ba60507 100644 --- a/platform/osx/audio_driver_osx.cpp +++ b/platform/osx/audio_driver_osx.cpp @@ -58,14 +58,14 @@ Error AudioDriverOSX::initDevice() { AudioStreamBasicDescription strdesc; - // TODO: Implement this - /*zeromem(&strdesc, sizeof(strdesc)); + zeromem(&strdesc, sizeof(strdesc)); UInt32 size = sizeof(strdesc); result = AudioUnitGetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &strdesc, &size); ERR_FAIL_COND_V(result != noErr, FAILED); switch (strdesc.mChannelsPerFrame) { case 2: // Stereo + case 4: // Surround 3.1 case 6: // Surround 5.1 case 8: // Surround 7.1 channels = strdesc.mChannelsPerFrame; @@ -75,7 +75,7 @@ Error AudioDriverOSX::initDevice() { // Unknown number of channels, default to stereo channels = 2; break; - }*/ + } mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE); @@ -103,7 +103,8 @@ Error AudioDriverOSX::initDevice() { samples_in.resize(buffer_size); if (OS::get_singleton()->is_stdout_verbose()) { - print_line("audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); + print_line("CoreAudio: detected " + itos(channels) + " channels"); + print_line("CoreAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); } AURenderCallbackStruct callback; @@ -242,7 +243,7 @@ int AudioDriverOSX::get_mix_rate() const { }; AudioDriver::SpeakerMode AudioDriverOSX::get_speaker_mode() const { - return SPEAKER_MODE_STEREO; + return get_speaker_mode_by_total_channels(channels); }; void AudioDriverOSX::lock() { diff --git a/platform/osx/crash_handler_osx.h b/platform/osx/crash_handler_osx.h new file mode 100644 index 0000000000..ff037e6b7a --- /dev/null +++ b/platform/osx/crash_handler_osx.h @@ -0,0 +1,47 @@ +/*************************************************************************/ +/* crash_handler_osx.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef CRASH_HANDLER_OSX_H +#define CRASH_HANDLER_OSX_H + +class CrashHandler { + + bool disabled; + +public: + void initialize(); + + void disable(); + bool is_disabled() const { return disabled; }; + + CrashHandler(); + ~CrashHandler(); +}; + +#endif diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm new file mode 100644 index 0000000000..9239573734 --- /dev/null +++ b/platform/osx/crash_handler_osx.mm @@ -0,0 +1,178 @@ +/*************************************************************************/ +/* crash_handler_osx.mm */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "main/main.h" +#include "os_osx.h" + +#include <string.h> +#include <unistd.h> + +// Note: Dump backtrace in 32bit mode is getting a bus error on the fgets by the ->execute, so enable only on 64bit +#if defined(DEBUG_ENABLED) && defined(__x86_64__) +#define CRASH_HANDLER_ENABLED 1 +#endif + +#ifdef CRASH_HANDLER_ENABLED +#include <cxxabi.h> +#include <dlfcn.h> +#include <execinfo.h> +#include <signal.h> + +#include <mach-o/dyld.h> +#include <mach-o/getsect.h> + +#ifdef __x86_64__ +static uint64_t load_address() { + const struct segment_command_64 *cmd = getsegbyname("__TEXT"); +#else +static uint32_t load_address() { + const struct segment_command *cmd = getsegbyname("__TEXT"); +#endif + char full_path[1024]; + uint32_t size = sizeof(full_path); + + if (cmd && !_NSGetExecutablePath(full_path, &size)) { + uint32_t dyld_count = _dyld_image_count(); + for (uint32_t i = 0; i < dyld_count; i++) { + const char *image_name = _dyld_get_image_name(i); + if (image_name && strncmp(image_name, full_path, 1024) == 0) { + return cmd->vmaddr + _dyld_get_image_vmaddr_slide(i); + } + } + } + + return 0; +} + +static void handle_crash(int sig) { + if (OS::get_singleton() == NULL) + return; + + void *bt_buffer[256]; + size_t size = backtrace(bt_buffer, 256); + String _execpath = OS::get_singleton()->get_executable_path(); + String msg = GLOBAL_GET("debug/settings/backtrace/message"); + + // Dump the backtrace to stderr with a message to the user + fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); + fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); + char **strings = backtrace_symbols(bt_buffer, size); + if (strings) { + void *load_addr = (void *)load_address(); + + for (int i = 1; i < size; i++) { + char fname[1024]; + Dl_info info; + + snprintf(fname, 1024, "%s", strings[i]); + + // Try to demangle the function name to provide a more readable one + if (dladdr(bt_buffer[i], &info) && info.dli_sname) { + if (info.dli_sname[0] == '_') { + int status; + char *demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status); + + if (status == 0 && demangled) { + snprintf(fname, 1024, "%s", demangled); + } + + if (demangled) + free(demangled); + } + } + + String output = fname; + + // Try to get the file/line number using atos + if (bt_buffer[i] > (void *)0x0 && OS::get_singleton()) { + List<String> args; + char str[1024]; + + args.push_back("-o"); + args.push_back(_execpath); + args.push_back("-arch"); +#ifdef __x86_64__ + args.push_back("x86_64"); +#else + args.push_back("i386"); +#endif + args.push_back("-l"); + snprintf(str, 1024, "%p", load_addr); + args.push_back(str); + snprintf(str, 1024, "%p", bt_buffer[i]); + args.push_back(str); + + int ret; + String out = ""; + Error err = OS::get_singleton()->execute(String("atos"), args, true, NULL, &out, &ret); + if (err == OK && out.substr(0, 2) != "0x") { + out.erase(out.length() - 1, 1); + output = out; + } + } + + fprintf(stderr, "[%d] %ls\n", i, output.c_str()); + } + + free(strings); + } + fprintf(stderr, "-- END OF BACKTRACE --\n"); + + // Abort to pass the error to the OS + abort(); +} +#endif + +CrashHandler::CrashHandler() { + disabled = false; +} + +CrashHandler::~CrashHandler() { +} + +void CrashHandler::disable() { + if (disabled) + return; + +#ifdef CRASH_HANDLER_ENABLED + signal(SIGSEGV, NULL); + signal(SIGFPE, NULL); + signal(SIGILL, NULL); +#endif + + disabled = true; +} + +void CrashHandler::initialize() { +#ifdef CRASH_HANDLER_ENABLED + signal(SIGSEGV, handle_crash); + signal(SIGFPE, handle_crash); + signal(SIGILL, handle_crash); +#endif +} diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h index c988dfe425..9a7773f5ee 100644 --- a/platform/osx/dir_access_osx.h +++ b/platform/osx/dir_access_osx.h @@ -46,6 +46,9 @@ class DirAccessOSX : public DirAccessUnix { protected: virtual String fix_unicode_name(const char *p_name) const; + + virtual int get_drive_count(); + virtual String get_drive(int p_drive); }; #endif //UNIX ENABLED diff --git a/platform/osx/dir_access_osx.mm b/platform/osx/dir_access_osx.mm index 6e8ceb5e19..6121e6ccfb 100644 --- a/platform/osx/dir_access_osx.mm +++ b/platform/osx/dir_access_osx.mm @@ -33,7 +33,8 @@ #include <errno.h> -#include <Foundation/NSString.h> +#include <AppKit/NSWorkspace.h> +#include <Foundation/Foundation.h> String DirAccessOSX::fix_unicode_name(const char *p_name) const { @@ -45,4 +46,19 @@ String DirAccessOSX::fix_unicode_name(const char *p_name) const { return fname; } +int DirAccessOSX::get_drive_count() { + NSArray *vols = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + return [vols count]; +} + +String DirAccessOSX::get_drive(int p_drive) { + NSArray *vols = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + int count = [vols count]; + + ERR_FAIL_INDEX_V(p_drive, count, ""); + + NSString *path = vols[p_drive]; + return String([path UTF8String]); +} + #endif //posix_enabled diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 7f749030ec..2ec76fe0dd 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -88,8 +88,15 @@ public: }; void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) { - - // what does this need to do? + if (p_preset->get("texture_format/s3tc")) { + r_features->push_back("s3tc"); + } + if (p_preset->get("texture_format/etc")) { + r_features->push_back("etc"); + } + if (p_preset->get("texture_format/etc2")) { + r_features->push_back("etc2"); + } } void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) { @@ -112,6 +119,10 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements"), "")); #endif + + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false)); } void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) { diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm index 83d782cc2f..e2740fc666 100644 --- a/platform/osx/godot_main_osx.mm +++ b/platform/osx/godot_main_osx.mm @@ -35,7 +35,6 @@ #include <unistd.h> int main(int argc, char **argv) { - int first_arg = 1; const char *dbg_arg = "-NSDocumentRevisionsDebugMode"; printf("arguments\n"); @@ -74,6 +73,13 @@ int main(int argc, char **argv) { } } +#ifdef DEBUG_ENABLED + // lets report the path we made current after all that + char cwd[4096]; + getcwd(cwd, 4096); + printf("Current path: %s\n", cwd); +#endif + OS_OSX os; Error err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index ebaebd84ce..059dd5afd0 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -30,6 +30,7 @@ #ifndef OS_OSX_H #define OS_OSX_H +#include "crash_handler_osx.h" #include "drivers/alsa/audio_driver_alsa.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/unix/os_unix.h" @@ -110,6 +111,8 @@ public: power_osx *power_manager; + CrashHandler crash_handler; + float _mouse_scale(float p_scale) { if (display_scale > 1.0) return p_scale; @@ -181,6 +184,7 @@ public: virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const; virtual String get_executable_path() const; + virtual String get_resource_dir() const; virtual LatinKeyboardVariant get_latin_keyboard_variant() const; @@ -212,7 +216,7 @@ public: virtual void set_ime_position(const Point2 &p_pos); virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp); - virtual PowerState get_power_state(); + virtual OS::PowerState get_power_state(); virtual int get_power_seconds_left(); virtual int get_power_percent_left(); @@ -223,6 +227,9 @@ public: void set_mouse_mode(MouseMode p_mode); MouseMode get_mouse_mode() const; + void disable_crash_handler(); + bool is_disable_crash_handler() const; + OS_OSX(); }; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index f502fb9a9c..111cdb0cf1 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -910,6 +910,8 @@ OS::VideoMode OS_OSX::get_default_video_mode() const { void OS_OSX::initialize_core() { + crash_handler.initialize(); + OS_Unix::initialize_core(); DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES); @@ -1086,12 +1088,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au visual_server->init(); // visual_server->cursor_set_visible(false, 0); - AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - - if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) { - - ERR_PRINT("Initializing audio failed."); - } + AudioDriverManager::initialize(p_audio_driver); // physics_server = memnew(PhysicsServerSW); @@ -1736,6 +1733,17 @@ String OS_OSX::get_executable_path() const { } } +String OS_OSX::get_resource_dir() const { + // start with our executable path + String path = get_executable_path(); + + int pos = path.find_last("/Contents/MacOS/"); + if (pos < 0) + return OS::get_resource_dir(); + + return path.substr(0, pos) + "/Contents/Resources/"; +} + // Returns string representation of keys, if they are printable. // static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) { @@ -1901,7 +1909,7 @@ String OS_OSX::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } -PowerState OS_OSX::get_power_state() { +OS::PowerState OS_OSX::get_power_state() { return power_manager->get_power_state(); } @@ -2011,3 +2019,11 @@ OS_OSX::OS_OSX() { bool OS_OSX::_check_internal_feature_support(const String &p_feature) { return p_feature == "pc" || p_feature == "s3tc"; } + +void OS_OSX::disable_crash_handler() { + crash_handler.disable(); +} + +bool OS_OSX::is_disable_crash_handler() const { + return crash_handler.is_disabled(); +} diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp index 5f3938cb91..eed03e63c1 100644 --- a/platform/osx/power_osx.cpp +++ b/platform/osx/power_osx.cpp @@ -174,7 +174,7 @@ bool power_osx::GetPowerInfo_MacOSX() { nsecs_left = -1; percent_left = -1; - power_state = POWERSTATE_UNKNOWN; + power_state = OS::POWERSTATE_UNKNOWN; if (blob != NULL) { CFArrayRef list = IOPSCopyPowerSourcesList(blob); @@ -194,13 +194,13 @@ bool power_osx::GetPowerInfo_MacOSX() { } if (!have_battery) { - power_state = POWERSTATE_NO_BATTERY; + power_state = OS::POWERSTATE_NO_BATTERY; } else if (charging) { - power_state = POWERSTATE_CHARGING; + power_state = OS::POWERSTATE_CHARGING; } else if (have_ac) { - power_state = POWERSTATE_CHARGED; + power_state = OS::POWERSTATE_CHARGED; } else { - power_state = POWERSTATE_ON_BATTERY; + power_state = OS::POWERSTATE_ON_BATTERY; } CFRelease(list); @@ -218,11 +218,11 @@ bool power_osx::UpdatePowerInfo() { return false; } -PowerState power_osx::get_power_state() { +OS::PowerState power_osx::get_power_state() { if (UpdatePowerInfo()) { return power_state; } else { - return POWERSTATE_UNKNOWN; + return OS::POWERSTATE_UNKNOWN; } } @@ -243,7 +243,7 @@ int power_osx::get_power_percent_left() { } power_osx::power_osx() - : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + : nsecs_left(-1), percent_left(-1), power_state(OS::POWERSTATE_UNKNOWN) { } power_osx::~power_osx() { diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h index 692c850d7c..20e47e9cd9 100644 --- a/platform/osx/power_osx.h +++ b/platform/osx/power_osx.h @@ -33,7 +33,7 @@ #include "dir_access_osx.h" #include "os/file_access.h" -#include "os/power.h" +#include "os/os.h" #include <CoreFoundation/CoreFoundation.h> class power_osx { @@ -41,7 +41,7 @@ class power_osx { private: int nsecs_left; int percent_left; - PowerState power_state; + OS::PowerState power_state; void checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging); bool GetPowerInfo_MacOSX(/*PowerState * state, int *seconds, int *percent*/); bool UpdatePowerInfo(); @@ -50,7 +50,7 @@ public: power_osx(); virtual ~power_osx(); - PowerState get_power_state(); + OS::PowerState get_power_state(); int get_power_seconds_left(); int get_power_percent_left(); }; |