Use thread_stack_pcs/GetGlobalMouse (10.1) instead of backtrace/HIGetMousePosition (10.5), this makes the game compatible with Tiger

This commit is contained in:
UnknownShadow200 2019-08-09 20:11:53 +10:00
parent 9a620753b6
commit 49714a38fb
2 changed files with 35 additions and 18 deletions

View File

@ -347,31 +347,50 @@ void Logger_Backtrace(String* trace, void* ctx) {
String_AppendConst(trace, _NL); String_AppendConst(trace, _NL);
} }
#elif defined CC_BUILD_POSIX #elif defined CC_BUILD_POSIX
#include <execinfo.h>
#define __USE_GNU #define __USE_GNU
#include <dlfcn.h> #include <dlfcn.h>
#undef __USE_GNU #undef __USE_GNU
void Logger_Backtrace(String* trace, void* ctx) { static void Logger_DumpFrame(String* trace, void* addr) {
String str; char strBuffer[384]; String str; char strBuffer[384];
void* addrs[40];
int i, frames;
Dl_info s; Dl_info s;
frames = backtrace(addrs, 40); String_InitArray(str, strBuffer);
for (i = 0; i < frames; i++) { s.dli_sname = NULL;
String_InitArray(str, strBuffer); s.dli_fname = NULL;
dladdr(addr, &s);
s.dli_sname = NULL; Logger_PrintFrame(&str, (uintptr_t)addr, (uintptr_t)s.dli_saddr, s.dli_sname, s.dli_fname);
s.dli_fname = NULL; String_AppendString(trace, &str);
dladdr(addrs[i], &s); Logger_Log(&str);
}
Logger_PrintFrame(&str, (uintptr_t)addrs[i], (uintptr_t)s.dli_saddr, s.dli_sname, s.dli_fname); #ifdef CC_BUILD_OSX
String_AppendString(trace, &str); void Logger_Backtrace(String* trace, void* ctx) {
Logger_Log(&str); void* addrs[40];
unsigned i, frames;
/* See lldb/tools/debugserver/source/MacOSX/stack_logging.h */
/* backtrace uses this internally too, and exists since OSX 10.1 */
extern void thread_stack_pcs(void** buffer, unsigned max, unsigned* nb);
thread_stack_pcs(addrs, 40, &frames);
for (i = 1; i < frames; i++) { /* 1 to skip thread_stack_pcs frame */
Logger_DumpFrame(trace, addrs[i]);
} }
String_AppendConst(trace, _NL); String_AppendConst(trace, _NL);
} }
#else
#include <execinfo.h>
void Logger_Backtrace(String* trace, void* ctx) {
void* addrs[40];
int i, frames = backtrace(addrs, 40);
for (i = 0; i < frames; i++) {
Logger_DumpFrame(trace, addrs[i]);
}
String_AppendConst(trace, _NL);
}
#endif
#endif #endif
static void Logger_DumpBacktrace(String* str, void* ctx) { static void Logger_DumpBacktrace(String* str, void* ctx) {
static const String backtrace = String_FromConst("-- backtrace --" _NL); static const String backtrace = String_FromConst("-- backtrace --" _NL);

View File

@ -1961,11 +1961,9 @@ void Window_ProcessEvents(void) {
} }
static void Cursor_GetRawPos(int* x, int* y) { static void Cursor_GetRawPos(int* x, int* y) {
HIPoint point; Point point;
/* NOTE: HIGetMousePosition is OSX 10.5 or later */ GetGlobalMouse(&point);
/* TODO: Use GetGlobalMouse instead!!!! */ *x = (int)point.h; *y = (int)point.v;
HIGetMousePosition(kHICoordSpaceScreenPixel, NULL, &point);
*x = (int)point.x; *y = (int)point.y;
} }
void Cursor_SetPosition(int x, int y) { void Cursor_SetPosition(int x, int y) {