Skip to content

Commit

Permalink
Fix Wesnoth crashing upon encountering XCode debug arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 22, 2016
1 parent 1d67892 commit 5aa1b73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Expand Up @@ -6,10 +6,10 @@

#import "SDL.h"
#import "SDLMain.h"
#include <vector>

extern int wesnoth_main(int argc, char **argv);
static int gArgc;
static char **gArgv;
extern "C" int wesnoth_main(int argc, char **argv);
static std::vector<char*> gArgs;

@interface SDLApplication : NSApplication
@end
Expand Down Expand Up @@ -70,41 +70,46 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note

/* Set the working directory to the .app's Resources directory */
chdir([[[NSBundle mainBundle] resourcePath] fileSystemRepresentation]);
//setenv("PYTHONHOME", ".", 1); //not needed because we don't use Python anymore

/* Hand off to main application code */
status = wesnoth_main (gArgc, gArgv);
status = wesnoth_main(gArgs.size() - 1, gArgs.data());

/* We're done, thank you for playing */
exit(status);
}
@end

template<int sz>
bool str_eq(const char* str, const char(& cstr)[sz]) {
return strncmp(str, cstr, sz) == 0;
}

#ifdef main
# undef main
#endif

/* Main entry point to executable - should *not* be SDL_main! */
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
int i;

/* This is passed if we are launched by double-clicking */
if (argc >= 2 && strncmp (argv[1], "-psn", 4) == 0)
{
gArgc = 1;
} else {
gArgc = argc;
gArgs.push_back(argv[0]); // Program name
for (int i = 1; i < argc; i++) {
// Filter out debug arguments that XCode might pass
if (str_eq(argv[i], "-ApplePersistenceIgnoreState")) {
i++; // Skip the argument
continue;
}
if (str_eq(argv[i], "-NSDocumentRevisionsDebugMode")) {
i++; // Skip the argument
continue;
}
// This is passed if launched by double-clicking
if (strncmp(argv[i], "-psn", 4) == 0) {
continue;
}
gArgs.push_back(argv[i]);
}
gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
assert (gArgv != NULL);
for (i = 0; i < gArgc; i++)
gArgv[i] = argv[i];
gArgv[i] = NULL;

// [SDLApplication poseAsClass:[NSApplication class]];
// NSApplicationMain (argc, argv);
gArgs.push_back(NULL);

[SDLApplication sharedApplication];
[NSBundle loadNibNamed:@"SDLMain" owner:NSApp];
[NSApp run];
Expand Down
8 changes: 4 additions & 4 deletions projectfiles/Xcode/Wesnoth.xcodeproj/project.pbxproj
Expand Up @@ -286,7 +286,7 @@
B552D92F108694BB002D8F86 /* ca_testing_move_to_targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92A108694BB002D8F86 /* ca_testing_move_to_targets.cpp */; };
B553B6BA12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
B553B6BB12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
B559986C0EC616B3008DD061 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = B559986B0EC616B3008DD061 /* SDLMain.m */; settings = {COMPILER_FLAGS = "-w"; }; };
B559986C0EC616B3008DD061 /* SDLMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = B559986B0EC616B3008DD061 /* SDLMain.mm */; settings = {COMPILER_FLAGS = "-w"; }; };
B55998F80EC61EA5008DD061 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55998F70EC61EA5008DD061 /* SDL2.framework */; };
B55999250EC61F59008DD061 /* SDL2_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999220EC61F59008DD061 /* SDL2_image.framework */; };
B55999260EC61F59008DD061 /* SDL2_net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B55999230EC61F59008DD061 /* SDL2_net.framework */; };
Expand Down Expand Up @@ -1538,7 +1538,7 @@
B553B6B812189C5900CC8C58 /* utility.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utility.cpp; sourceTree = "<group>"; };
B553B6B912189C5900CC8C58 /* utility.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utility.hpp; sourceTree = "<group>"; };
B559986A0EC616B3008DD061 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLMain.h; path = "Mac Sources/SDLMain.h"; sourceTree = "<group>"; };
B559986B0EC616B3008DD061 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLMain.m; path = "Mac Sources/SDLMain.m"; sourceTree = "<group>"; };
B559986B0EC616B3008DD061 /* SDLMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SDLMain.mm; path = "Mac Sources/SDLMain.mm"; sourceTree = "<group>"; };
B55998F70EC61EA5008DD061 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = lib/SDL2.framework; sourceTree = "<group>"; };
B55999220EC61F59008DD061 /* SDL2_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_image.framework; path = lib/SDL2_image.framework; sourceTree = "<group>"; };
B55999230EC61F59008DD061 /* SDL2_net.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_net.framework; path = lib/SDL2_net.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2446,7 +2446,7 @@
F40A13BD1A3AA56800C4D071 /* apple_notification.hpp */,
F40A13BB1A3A88BA00C4D071 /* apple_notification.mm */,
B559986A0EC616B3008DD061 /* SDLMain.h */,
B559986B0EC616B3008DD061 /* SDLMain.m */,
B559986B0EC616B3008DD061 /* SDLMain.mm */,
B5BB6CD80F89470B00444FBF /* server_main.m */,
32CA4F630368D1EE00C91783 /* Wesnoth_Prefix.pch */,
);
Expand Down Expand Up @@ -4753,7 +4753,7 @@
B5599ADE0EC62181008DD061 /* scrollbar.cpp in Sources */,
B5A9BD6A0ECA805A002BE442 /* scrollbar.cpp in Sources */,
B5599ADF0EC62181008DD061 /* scrollpane.cpp in Sources */,
B559986C0EC616B3008DD061 /* SDLMain.m in Sources */,
B559986C0EC616B3008DD061 /* SDLMain.mm in Sources */,
EC64D7611A085CE60092EF75 /* seed_rng.cpp in Sources */,
B5599B030EC62181008DD061 /* settings.cpp in Sources */,
B5A9BD6B0ECA805A002BE442 /* settings.cpp in Sources */,
Expand Down

0 comments on commit 5aa1b73

Please sign in to comment.