Skip to content
Permalink
Browse files

Use thread_stack_pcs/GetGlobalMouse (10.1) instead of backtrace/HIGet…

…MousePosition (10.5), this makes the game compatible with Tiger
  • Loading branch information...
UnknownShadow200 committed Aug 9, 2019
1 parent 9a62075 commit 49714a38fb63906dbfdae35d6a3babc80f508b22
Showing with 35 additions and 18 deletions.
  1. +32 −13 src/Logger.c
  2. +3 −5 src/Window.c
@@ -347,32 +347,51 @@ void Logger_Backtrace(String* trace, void* ctx) {
String_AppendConst(trace, _NL);
}
#elif defined CC_BUILD_POSIX
#include <execinfo.h>
#define __USE_GNU
#include <dlfcn.h>
#undef __USE_GNU

void Logger_Backtrace(String* trace, void* ctx) {
static void Logger_DumpFrame(String* trace, void* addr) {
String str; char strBuffer[384];
void* addrs[40];
int i, frames;
Dl_info s;

frames = backtrace(addrs, 40);
for (i = 0; i < frames; i++) {
String_InitArray(str, strBuffer);
String_InitArray(str, strBuffer);
s.dli_sname = NULL;
s.dli_fname = NULL;
dladdr(addr, &s);

s.dli_sname = NULL;
s.dli_fname = NULL;
dladdr(addrs[i], &s);
Logger_PrintFrame(&str, (uintptr_t)addr, (uintptr_t)s.dli_saddr, s.dli_sname, s.dli_fname);
String_AppendString(trace, &str);
Logger_Log(&str);
}

Logger_PrintFrame(&str, (uintptr_t)addrs[i], (uintptr_t)s.dli_saddr, s.dli_sname, s.dli_fname);
String_AppendString(trace, &str);
Logger_Log(&str);
#ifdef CC_BUILD_OSX
void Logger_Backtrace(String* trace, void* ctx) {
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);
}
#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
static void Logger_DumpBacktrace(String* str, void* ctx) {
static const String backtrace = String_FromConst("-- backtrace --" _NL);
Logger_Log(&backtrace);
@@ -1961,11 +1961,9 @@ void Window_ProcessEvents(void) {
}

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

void Cursor_SetPosition(int x, int y) {

0 comments on commit 49714a3

Please sign in to comment.
You can’t perform that action at this time.