From 164a076bfe60855d4d12ef5b51de3fad67c67d23 Mon Sep 17 00:00:00 2001 From: Cinder Biscuits <cinder@cinderblocks.biz> Date: Sat, 17 Aug 2019 12:02:38 -0500 Subject: [PATCH] Turn on Obj-C ARC, fix a memleak in doSaveDialog() --- indra/cmake/00-Common.cmake | 2 +- indra/cmake/Variables.cmake | 44 ++-- indra/llplugin/slplugin/slplugin-objc.h | 4 +- indra/llplugin/slplugin/slplugin-objc.mm | 48 ++-- indra/llplugin/slplugin/slplugin.cpp | 21 -- indra/llvfs/llvfs_objc.mm | 11 - indra/llwindow/llappdelegate-objc.h | 6 +- indra/llwindow/llopenglview-objc.mm | 148 ++++++------- indra/llwindow/llwindowmacosx-objc.mm | 207 +++++++++--------- indra/newview/llappdelegate-objc.mm | 143 ------------ indra/newview/llappviewermacosx-objc.mm | 12 +- indra/newview/lldesktopnotificationsmacosx.mm | 3 - indra/newview/llfilepicker.cpp | 6 +- indra/newview/llfilepicker_mac.h | 2 +- indra/newview/llfilepicker_mac.mm | 11 +- 15 files changed, 223 insertions(+), 445 deletions(-) diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake index 8065f303a1..38a9909156 100644 --- a/indra/cmake/00-Common.cmake +++ b/indra/cmake/00-Common.cmake @@ -281,7 +281,7 @@ if (DARWIN) add_definitions(-DLL_DARWIN=1) set(CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names,-search_paths_first") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_LINK_FLAGS}") - set(DARWIN_extra_cstar_flags "-g") + set(DARWIN_extra_cstar_flags "-g -fobjc-arc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DARWIN_extra_cstar_flags}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DARWIN_extra_cstar_flags}") # NOTE: it's critical that the optimization flag is put in front. diff --git a/indra/cmake/Variables.cmake b/indra/cmake/Variables.cmake index 8bf6806ffc..615058f3ad 100644 --- a/indra/cmake/Variables.cmake +++ b/indra/cmake/Variables.cmake @@ -220,49 +220,47 @@ endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(DARWIN ON BOOL FORCE) - + + # Xcode setup if (XCODE_VERSION LESS 9.0.0) message( FATAL_ERROR "Xcode 9.0.0 or greater is required." ) endif (XCODE_VERSION LESS 9.0.0) message( "Building with " ${CMAKE_OSX_SYSROOT} ) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13) + # Compiler setup set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0") set(CMAKE_XCODE_ATTRIBUTE_GCC_OPTIMIZATION_LEVEL fast) set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO) set(CMAKE_XCODE_ATTRIBUTE_GCC_FAST_MATH YES) - set(CMAKE_XCODE_ATTRIBUTE_GCC_FAST_OBJC_DISPATCH YES) - set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES) - set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") -set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17") + if (${CMAKE_BUILD_TYPE} STREQUAL "Release") + set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym) + else (${CMAKE_BUILD_TYPE} STREQUAL "Release") + set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf) + endif (${CMAKE_BUILD_TYPE} STREQUAL "Release") + if (USE_AVX2) set(CMAKE_XCODE_ATTRIBUTE_CLANG_X86_VECTOR_INSTRUCTIONS avx2) elseif (USE_AVX) set(CMAKE_XCODE_ATTRIBUTE_CLANG_X86_VECTOR_INSTRUCTIONS avx) else () - set(CMAKE_XCODE_ATTRIBUTE_CLANG_X86_VECTOR_INSTRUCTIONS sse4.2) + set(CMAKE_XCODE_ATTRIBUTE_CLANG_X86_VECTOR_INSTRUCTIONS sse4.2) endif () - if (${CMAKE_BUILD_TYPE} STREQUAL "Release") - set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym) - else (${CMAKE_BUILD_TYPE} STREQUAL "Release") - set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf) - endif (${CMAKE_BUILD_TYPE} STREQUAL "Release") + # C++ specifics + set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") + + # Objective C compiler setup + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES) + set(CMAKE_XCODE_ATTRIBUTE_GCC_FAST_OBJC_DISPATCH YES) + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES) + set(ADDRESS_SIZE 64) - if (NOT CMAKE_OSX_ARCHITECTURES) - if (ADDRESS_SIZE EQUAL 64) - set(CMAKE_OSX_ARCHITECTURES x86_64) - else (ADDRESS_SIZE EQUAL 64) - set(CMAKE_OSX_ARCHITECTURES i386) - endif (ADDRESS_SIZE EQUAL 64) - endif (NOT CMAKE_OSX_ARCHITECTURES) + set(ARCH x86_64) + set(CMAKE_OSX_ARCHITECTURES x86_64) - if (ADDRESS_SIZE EQUAL 64) - set(ARCH x86_64) - else (ADDRESS_SIZE EQUAL 64) - set(ARCH i386) - endif (ADDRESS_SIZE EQUAL 64) set(LL_ARCH ${ARCH}_darwin) set(LL_ARCH_DIR universal-darwin) set(AUTOBUILD_PLATFORM_NAME "darwin" CACHE STRING "Autobuild Platform Name") diff --git a/indra/llplugin/slplugin/slplugin-objc.h b/indra/llplugin/slplugin/slplugin-objc.h index af0ebe1af2..e09e0be959 100644 --- a/indra/llplugin/slplugin/slplugin-objc.h +++ b/indra/llplugin/slplugin/slplugin-objc.h @@ -40,13 +40,11 @@ class LLCocoaPlugin public: LLCocoaPlugin(); void setupCocoa(); - void createAutoReleasePool(); - void deleteAutoReleasePool(); void setupGroup(); void updateWindows(); void processEvents(); public: - //EventTargetRef mEventTarget; + NSWindow* mFrontWindow; NSWindow* mPluginWindow; int mHackState; diff --git a/indra/llplugin/slplugin/slplugin-objc.mm b/indra/llplugin/slplugin/slplugin-objc.mm index 0f3f8edcb9..f3457ac7a4 100644 --- a/indra/llplugin/slplugin/slplugin-objc.mm +++ b/indra/llplugin/slplugin/slplugin-objc.mm @@ -42,44 +42,23 @@ void LLCocoaPlugin::setupCocoa() if(!inited) { - createAutoReleasePool(); - - // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents. - // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' - // when init'ing the Cocoa App window. - [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; + @autoreleasepool { + // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents. + // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' + // when init'ing the Cocoa App window. + [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; - // Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image - [[[NSWindow alloc] init] release]; - - mPluginWindow = [NSApp mainWindow]; - - deleteAutoReleasePool(); + // Grief NSWindow machinery set up so that NSCursor can use a window to cache the cursor image + (void)[[NSWindow alloc] init]; + + mPluginWindow = [NSApp mainWindow]; + } // @autoreleasepool inited = true; } } -static NSAutoreleasePool *sPool = NULL; - -void LLCocoaPlugin::createAutoReleasePool() -{ - if(!sPool) - { - sPool = [[NSAutoreleasePool alloc] init]; - } -} - -void LLCocoaPlugin::deleteAutoReleasePool() -{ - if(sPool) - { - [sPool release]; - sPool = NULL; - } -} - -LLCocoaPlugin::LLCocoaPlugin():mHackState(0) +LLCocoaPlugin::LLCocoaPlugin() : mHackState(0) { NSArray* window_list = [NSApp orderedWindows]; mFrontWindow = [window_list objectAtIndex:0]; @@ -88,8 +67,9 @@ LLCocoaPlugin::LLCocoaPlugin():mHackState(0) void LLCocoaPlugin::processEvents() { // Some plugins (webkit at least) will want an event loop. This qualifies. - NSEvent * event; - event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; + NSEvent * event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:NSDefaultRunLoopMode dequeue:YES]; [NSApp sendEvent: event]; } diff --git a/indra/llplugin/slplugin/slplugin.cpp b/indra/llplugin/slplugin/slplugin.cpp index 384c75049d..198494e8f3 100644 --- a/indra/llplugin/slplugin/slplugin.cpp +++ b/indra/llplugin/slplugin/slplugin.cpp @@ -227,17 +227,12 @@ int main(int argc, char **argv) LLCocoaPlugin cocoa_interface; cocoa_interface.setupCocoa(); - cocoa_interface.createAutoReleasePool(); #endif //LL_DARWIN LLPluginProcessChild *plugin = new LLPluginProcessChild(); plugin->init(port); -#if LL_DARWIN - cocoa_interface.deleteAutoReleasePool(); -#endif - LLTimer timer; timer.start(); @@ -253,9 +248,6 @@ int main(int argc, char **argv) #endif while(!plugin->isDone()) { -#if LL_DARWIN - cocoa_interface.createAutoReleasePool(); -#endif timer.reset(); plugin->idle(); #if LL_DARWIN @@ -285,19 +277,6 @@ int main(int argc, char **argv) // LL_INFOS("slplugin") << "slept for "<< timer.getElapsedTimeF64() * 1000.0f << " ms" << LL_ENDL; } - - -#if LL_WINDOWS - // More agressive checking of interfering exception handlers. - // Doesn't appear to be required so far - even for plugins - // that do crash with a single call to the intercept - // exception handler such as QuickTime. - //checkExceptionHandler(); -#endif - -#if LL_DARWIN - cocoa_interface.deleteAutoReleasePool(); -#endif } delete plugin; diff --git a/indra/llvfs/llvfs_objc.mm b/indra/llvfs/llvfs_objc.mm index 224050f90a..8c06baebf4 100644 --- a/indra/llvfs/llvfs_objc.mm +++ b/indra/llvfs/llvfs_objc.mm @@ -32,12 +32,10 @@ std::string getSystemTempFolder() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString * tempDir = NSTemporaryDirectory(); if (tempDir == nil) tempDir = @"/tmp"; std::string result([tempDir UTF8String]); - [pool release]; return result; } @@ -46,8 +44,6 @@ std::string getSystemTempFolder() std::string findSystemDirectory(NSSearchPathDirectory searchPathDirectory, NSSearchPathDomainMask domainMask) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - std::string result = ""; NSString *path = nil; @@ -66,28 +62,21 @@ std::string findSystemDirectory(NSSearchPathDirectory searchPathDirectory, result = [path UTF8String]; } - [pool release]; return result; } std::string getSystemExecutableFolder() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *bundlePath = [[NSBundle mainBundle] executablePath]; std::string result([bundlePath UTF8String]); - [pool release]; return result; } std::string getSystemResourceFolder() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *bundlePath = [[NSBundle mainBundle] resourcePath]; std::string result([bundlePath UTF8String]); - [pool release]; return result; } diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index 7d683288c5..715b7bfc3d 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -33,9 +33,9 @@ @interface LLAppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate> { - LLNSWindow *window; - NSWindow *inputWindow; - LLNonInlineTextView *inputView; + LLNSWindow __unsafe_unretained *window; + NSWindow __unsafe_unretained *inputWindow; + LLNonInlineTextView __unsafe_unretained *inputView; NSTimer *frameTimer; NSString *currentInputLanguage; } diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index cd13c5c2fb..a2b395ee53 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -204,7 +204,6 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; } - (id) init @@ -226,57 +225,56 @@ attributedStringInfo getSegments(NSAttributedString *str) { self = [super initWithFrame:frame]; if (!self) { return self; } // Despite what this may look like, returning nil self is a-ok. - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; - - // Initialize with a default "safe" pixel format that will work with versions dating back to OS X 10.6. - // Any specialized pixel formats, i.e. a core profile pixel format, should be initialized through rebuildContextWithFormat. - // 10.7 and 10.8 don't really care if we're defining a profile or not. If we don't explicitly request a core or legacy profile, it'll always assume a legacy profile (for compatibility reasons). - NSOpenGLPixelFormatAttribute attrs[] = { - NSOpenGLPFANoRecovery, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAClosestPolicy, - NSOpenGLPFAAccelerated, - NSOpenGLPFAMultisample, - NSOpenGLPFASampleBuffers, static_cast<NSOpenGLPixelFormatAttribute>((samples > 0 ? 1 : 0)), - NSOpenGLPFASamples, static_cast<NSOpenGLPixelFormatAttribute>(samples), - NSOpenGLPFAStencilSize, static_cast<NSOpenGLPixelFormatAttribute>(8), - NSOpenGLPFADepthSize, static_cast<NSOpenGLPixelFormatAttribute>(24), - NSOpenGLPFAAlphaSize, static_cast<NSOpenGLPixelFormatAttribute>(8), - NSOpenGLPFAColorSize, static_cast<NSOpenGLPixelFormatAttribute>(24), - 0 - }; - - NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease]; - - if (pixelFormat == nil) - { - NSLog(@"Failed to create pixel format!", nil); - return nil; - } - - NSOpenGLContext *glContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease]; - - if (glContext == nil) - { - NSLog(@"Failed to create OpenGL context!", nil); - return nil; - } + @autoreleasepool { + [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; + + // Initialize with a default "safe" pixel format that will work with versions dating back to OS X 10.6. + // Any specialized pixel formats, i.e. a core profile pixel format, should be initialized through rebuildContextWithFormat. + // 10.7 and 10.8 don't really care if we're defining a profile or not. If we don't explicitly request a core or legacy profile, it'll always assume a legacy profile (for compatibility reasons). + NSOpenGLPixelFormatAttribute attrs[] = { + NSOpenGLPFANoRecovery, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAClosestPolicy, + NSOpenGLPFAAccelerated, + NSOpenGLPFAMultisample, + NSOpenGLPFASampleBuffers, static_cast<NSOpenGLPixelFormatAttribute>((samples > 0 ? 1 : 0)), + NSOpenGLPFASamples, static_cast<NSOpenGLPixelFormatAttribute>(samples), + NSOpenGLPFAStencilSize, static_cast<NSOpenGLPixelFormatAttribute>(8), + NSOpenGLPFADepthSize, static_cast<NSOpenGLPixelFormatAttribute>(24), + NSOpenGLPFAAlphaSize, static_cast<NSOpenGLPixelFormatAttribute>(8), + NSOpenGLPFAColorSize, static_cast<NSOpenGLPixelFormatAttribute>(24), + 0 + }; + + NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; + + if (pixelFormat == nil) + { + NSLog(@"Failed to create pixel format!", nil); + return nil; + } + + NSOpenGLContext *glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; + + if (glContext == nil) + { + NSLog(@"Failed to create OpenGL context!", nil); + return nil; + } - [self setWantsBestResolutionOpenGLSurface:YES]; + [self setWantsBestResolutionOpenGLSurface:YES]; - [self setPixelFormat:pixelFormat]; + [self setPixelFormat:pixelFormat]; - [self setOpenGLContext:glContext]; - - [glContext setView:self]; - - [glContext makeCurrentContext]; - - GLint glVsync = vsync ? 1 : 0; - [glContext setValues:&glVsync forParameter:NSOpenGLCPSwapInterval]; - - [pool release]; + [self setOpenGLContext:glContext]; + + [glContext setView:self]; + + [glContext makeCurrentContext]; + + GLint glVsync = vsync ? 1 : 0; + [glContext setValues:&glVsync forParameter:NSOpenGLCPSwapInterval]; + } // @autoreleasepool return self; } @@ -287,22 +285,22 @@ attributedStringInfo getSegments(NSAttributedString *str) - (BOOL) rebuildContextWithFormat:(NSOpenGLPixelFormat *)format { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSOpenGLContext *ctx = [self openGLContext]; - - [ctx clearDrawable]; - ctx = [[[NSOpenGLContext alloc] initWithFormat:format shareContext:nil] autorelease]; - - if (ctx == nil) - { - NSLog(@"Failed to create OpenGL context!", nil); - return false; - } - - [self setOpenGLContext:ctx]; - [ctx setView:self]; - [ctx makeCurrentContext]; - [pool release]; + @autoreleasepool { + NSOpenGLContext *ctx = [self openGLContext]; + + [ctx clearDrawable]; + ctx = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil]; + + if (ctx == nil) + { + NSLog(@"Failed to create OpenGL context!", nil); + return false; + } + + [self setOpenGLContext:ctx]; + [ctx setView:self]; + [ctx makeCurrentContext]; + } // @autoreleasepool return true; } @@ -730,16 +728,16 @@ attributedStringInfo getSegments(NSAttributedString *str) @implementation LLNonInlineTextView /* Input Window is a legacy of 20 century, so we want to remove related classes. - But unfortunately, Viwer web browser has no support for modern inline input, - we need to leave these classes... - We will be back to get rid of Input Window after fixing viewer web browser. - - How Input Window should work: - 1) Input Window must not be empty. - It must close when it become empty result of edithing. - 2) Input Window must not close when it still has input data. - It must keep open user types next char before commit. by Pell Smit -*/ + * But unfortunately, Viwer web browser has no support for modern inline input, + * we need to leave these classes... + * We will be back to get rid of Input Window after fixing viewer web browser. + * + * How Input Window should work: + * 1) Input Window must not be empty. + * It must close when it become empty result of edithing. + * 2) Input Window must not close when it still has input data. + * It must keep open user types next char before commit. + */ - (void) setGLView:(LLOpenGLView *)view { diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index e731c4ac31..f1a806e754 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -49,14 +49,13 @@ void setupCocoa() if(!inited) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + @autoreleasepool { // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents. // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' // when init'ing the Cocoa App window. [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; - [pool release]; + } // @autoreleasepool inited = true; } @@ -64,13 +63,15 @@ void setupCocoa() bool copyToPBoard(const unsigned short *str, unsigned int len) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; + bool ret; + @autoreleasepool { NSPasteboard *pboard = [NSPasteboard generalPasteboard]; [pboard clearContents]; - NSArray *contentsToPaste = [[[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil] autorelease]; - BOOL ret = [pboard writeObjects:contentsToPaste]; - [pool release]; + NSArray *contentsToPaste = + [[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil]; + ret = [pboard writeObjects:contentsToPaste]; + } // @autoreleasepool return ret; } @@ -82,41 +83,30 @@ bool pasteBoardAvailable() const unsigned short *copyFromPBoard() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; - NSPasteboard *pboard = [NSPasteboard generalPasteboard]; - NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; - NSString *str = NULL; - BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; - if (ok) - { - NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]]; - str = [objToPaste objectAtIndex:0]; - } - NSUInteger len = [str length]; - unichar* temp = (unichar*)calloc(len+1, sizeof(unichar)); - [str getCharacters:temp range:NSMakeRange(0, len)]; + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; + NSString *str = NULL; + BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; + if (ok) + { + NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]]; + str = [objToPaste objectAtIndex:0]; + } + NSUInteger len = [str length]; + unichar *buffer = (unichar*)calloc(len+1, sizeof(unichar)); + [str getCharacters:buffer range:NSMakeRange(0, len)]; - [pool release]; - return temp; + return buffer; } CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - // extra retain on the NSCursor since we want it to live for the lifetime of the app. - NSCursor *cursor = - [[[NSCursor alloc] - initWithImage: - [[[NSImage alloc] initWithContentsOfFile: - [NSString stringWithFormat:@"%s", fullpath] - ]autorelease] - hotSpot:NSMakePoint(hotspotX, hotspotY) - ]retain]; + NSCursor *cursor = [[NSCursor alloc] + initWithImage: [[NSImage alloc] + initWithContentsOfFile: [NSString stringWithFormat:@"%s", fullpath]] + hotSpot: NSMakePoint(hotspotX, hotspotY)]; - [pool release]; - - return (CursorRef)cursor; + return (CursorRef)CFBridgingRetain(cursor); } void setArrowCursor() @@ -176,10 +166,9 @@ OSErr releaseImageCursor(CursorRef ref) { if( ref != NULL ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSCursor *cursor = (NSCursor*)ref; - [cursor release]; - [pool release]; + @autoreleasepool { + CFBridgingRelease(ref); + } // @autoreleasepool } else { @@ -193,10 +182,8 @@ OSErr setImageCursor(CursorRef ref) { if( ref != NULL ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSCursor *cursor = (NSCursor*)ref; - [cursor set]; - [pool release]; + NSCursor *cursor = (__bridge NSCursor*)ref; + [cursor set]; } else { @@ -215,53 +202,57 @@ NSWindowRef createNSWindow(int x, int y, int width, int height) styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTexturedBackgroundWindowMask backing:NSBackingStoreBuffered defer:NO]; [window makeKeyAndOrderFront:nil]; [window setAcceptsMouseMovedEvents:TRUE]; - return window; + return (NSWindowRef)CFBridgingRetain(window); } GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync) { - LLOpenGLView *glview = [[LLOpenGLView alloc]initWithFrame:[(LLNSWindow*)window frame] withSamples:samples andVsync:vsync]; - [(LLNSWindow*)window setContentView:glview]; - return glview; + LLOpenGLView *glview = [[LLOpenGLView alloc] + initWithFrame:[(__bridge LLNSWindow*)window frame] + withSamples:samples andVsync:vsync]; + [(__bridge LLNSWindow*)window setContentView:glview]; + return (GLViewRef)CFBridgingRetain(glview); } void glSwapBuffers(void* context) { - [(NSOpenGLContext*)context flushBuffer]; + [(__bridge NSOpenGLContext*)context flushBuffer]; } CGLContextObj getCGLContextObj(GLViewRef view) { - return [(LLOpenGLView *)view getCGLContextObj]; + return [(__bridge LLOpenGLView *)view getCGLContextObj]; } CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window) { - LLOpenGLView *glview = [(LLNSWindow*)window contentView]; + LLOpenGLView *glview = [(__bridge LLNSWindow*)window contentView]; return [glview getCGLPixelFormatObj]; } unsigned long getVramSize(GLViewRef view) { - return [(LLOpenGLView *)view getVramSize]; + return [(__bridge LLOpenGLView *)view getVramSize]; } float getDeviceUnitSize(GLViewRef view) { - return [(LLOpenGLView*)view convertSizeToBacking:NSMakeSize(1, 1)].width; + return [(__bridge LLOpenGLView*)view convertSizeToBacking:NSMakeSize(1, 1)].width; } void getContentViewBounds(NSWindowRef window, float* bounds) { - bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x; - bounds[1] = [[(LLNSWindow*)window contentView] bounds].origin.y; - bounds[2] = [[(LLNSWindow*)window contentView] bounds].size.width; - bounds[3] = [[(LLNSWindow*)window contentView] bounds].size.height; + bounds[0] = [[(__bridge LLNSWindow*)window contentView] bounds].origin.x; + bounds[1] = [[(__bridge LLNSWindow*)window contentView] bounds].origin.y; + bounds[2] = [[(__bridge LLNSWindow*)window contentView] bounds].size.width; + bounds[3] = [[(__bridge LLNSWindow*)window contentView] bounds].size.height; } void getScaledContentViewBounds(NSWindowRef window, GLViewRef view, float* bounds) { - NSRect b = [(NSOpenGLView*)view convertRectToBacking:[[(LLNSWindow*)window contentView] bounds]]; + NSRect b = [(__bridge NSOpenGLView*)view convertRectToBacking: + [[(__bridge LLNSWindow*)window contentView] + bounds]]; bounds[0] = b.origin.x; bounds[1] = b.origin.y; bounds[2] = b.size.width; @@ -270,7 +261,7 @@ void getScaledContentViewBounds(NSWindowRef window, GLViewRef view, float* bound void getWindowSize(NSWindowRef window, float* size) { - NSRect frame = [(LLNSWindow*)window frame]; + NSRect frame = [(__bridge LLNSWindow*)window frame]; size[0] = frame.origin.x; size[1] = frame.origin.y; size[2] = frame.size.width; @@ -279,10 +270,10 @@ void getWindowSize(NSWindowRef window, float* size) void setWindowSize(NSWindowRef window, int width, int height) { - NSRect frame = [(LLNSWindow*)window frame]; + NSRect frame = [(__bridge LLNSWindow*)window frame]; frame.size.width = width; frame.size.height = height; - [(LLNSWindow*)window setFrame:frame display:TRUE]; + [(__bridge LLNSWindow*)window setFrame:frame display:TRUE]; } void setWindowPos(NSWindowRef window, float* pos) @@ -290,26 +281,26 @@ void setWindowPos(NSWindowRef window, float* pos) NSPoint point; point.x = pos[0]; point.y = pos[1]; - [(LLNSWindow*)window setFrameOrigin:point]; + [(__bridge LLNSWindow*)window setFrameOrigin:point]; } void getCursorPos(NSWindowRef window, float* pos) { NSPoint mLoc; - mLoc = [(LLNSWindow*)window mouseLocationOutsideOfEventStream]; + mLoc = [(__bridge LLNSWindow*)window mouseLocationOutsideOfEventStream]; pos[0] = mLoc.x; pos[1] = mLoc.y; } void makeWindowOrderFront(NSWindowRef window) { - [(LLNSWindow*)window makeKeyAndOrderFront:nil]; + [(__bridge LLNSWindow*)window makeKeyAndOrderFront:nil]; } void convertScreenToWindow(NSWindowRef window, float *coord) { NSRect point = NSMakeRect(coord[0], coord[1], 0, 0); - point = [(LLNSWindow*)window convertRectFromScreen:point]; + point = [(__bridge LLNSWindow*)window convertRectFromScreen:point]; coord[0] = point.origin.x; coord[1] = point.origin.y; } @@ -317,7 +308,7 @@ void convertScreenToWindow(NSWindowRef window, float *coord) void convertRectToScreen(NSWindowRef window, float *coord) { NSRect point = NSMakeRect(coord[0], coord[1], coord[2], coord[3]); - point = [(LLNSWindow*)window convertRectToScreen:point]; + point = [(__bridge LLNSWindow*)window convertRectToScreen:point]; coord[0] = point.origin.x; coord[1] = point.origin.y; @@ -328,7 +319,7 @@ void convertRectToScreen(NSWindowRef window, float *coord) void convertRectFromScreen(NSWindowRef window, float *coord) { NSRect point = NSMakeRect(coord[0], coord[1], coord[2], coord[3]); - point = [(LLNSWindow*)window convertRectFromScreen:point]; + point = [(__bridge LLNSWindow*)window convertRectFromScreen:point]; coord[0] = point.origin.x; coord[1] = point.origin.y; @@ -338,7 +329,7 @@ void convertRectFromScreen(NSWindowRef window, float *coord) void convertWindowToScreen(NSWindowRef window, float *coord) { - LLNSWindow *nsWindow = (LLNSWindow*)window; + LLNSWindow *nsWindow = (__bridge LLNSWindow*)window; NSRect rect = NSMakeRect(coord[0], coord[1], 0, 0); rect = [nsWindow convertRectToScreen:rect]; NSRect screenRect = [[nsWindow screen] frame]; @@ -347,32 +338,32 @@ void convertWindowToScreen(NSWindowRef window, float *coord) coord[1] = retPoint.y; } -void closeWindow(NSWindowRef window) +void closeWindow(NSWindowRef windowRef) { - [(LLNSWindow*)window close]; - [(LLNSWindow*)window release]; + LLNSWindow *window = (LLNSWindow*)CFBridgingRelease(windowRef); + [window close]; } -void removeGLView(GLViewRef view) +void removeGLView(GLViewRef viewRef) { - [(LLOpenGLView*)view clearGLContext]; - [(LLOpenGLView*)view removeFromSuperview]; - [(LLOpenGLView*)view release]; + LLOpenGLView *view_ctx = (LLOpenGLView*)CFBridgingRelease(viewRef); + [(LLOpenGLView*)view_ctx clearGLContext]; + [(LLOpenGLView*)view_ctx removeFromSuperview]; } void setupInputWindow(NSWindowRef window, GLViewRef glview) { - [[(LLAppDelegate*)[NSApp delegate] inputView] setGLView:(LLOpenGLView*)glview]; + [[(LLAppDelegate*)[NSApp delegate] inputView] setGLView:(__bridge LLOpenGLView*)glview]; } void commitCurrentPreedit(GLViewRef glView) { - [(LLOpenGLView*)glView commitCurrentPreedit]; + [(__bridge LLOpenGLView*)glView commitCurrentPreedit]; } void allowDirectMarkedTextInput(bool allow, GLViewRef glView) { - [(LLOpenGLView*)glView allowMarkedTextInput:allow]; + [(__bridge LLOpenGLView*)glView allowMarkedTextInput:allow]; } NSWindowRef getMainAppWindow() @@ -380,12 +371,12 @@ NSWindowRef getMainAppWindow() LLNSWindow *winRef = [(LLAppDelegate*)[[LLNSApplication sharedApplication] delegate] window]; [winRef setAcceptsMouseMovedEvents:TRUE]; - return winRef; + return (NSWindowRef)CFBridgingRetain(winRef); } void makeFirstResponder(NSWindowRef window, GLViewRef view) { - [(LLNSWindow*)window makeFirstResponder:(LLOpenGLView*)view]; + [(__bridge LLNSWindow*)window makeFirstResponder:(__bridge LLOpenGLView*)view]; } void requestUserAttention() @@ -395,46 +386,48 @@ void requestUserAttention() long showAlert(std::string text, std::string title, int type) { - NSAlert *alert = [[NSAlert alloc] init]; - - [alert setMessageText:[NSString stringWithCString:title.c_str() encoding:[NSString defaultCStringEncoding]]]; - [alert setInformativeText:[NSString stringWithCString:text.c_str() encoding:[NSString defaultCStringEncoding]]]; - if (type == 0) - { - [alert addButtonWithTitle:@"Okay"]; - } else if (type == 1) - { - [alert addButtonWithTitle:@"Okay"]; - [alert addButtonWithTitle:@"Cancel"]; - } else if (type == 2) - { - [alert addButtonWithTitle:@"Yes"]; - [alert addButtonWithTitle:@"No"]; + NSModalResponse response; + @autoreleasepool { + + NSAlert *alert = [[NSAlert alloc] init]; + + [alert setMessageText:[NSString stringWithCString:title.c_str() encoding:[NSString defaultCStringEncoding]]]; + [alert setInformativeText:[NSString stringWithCString:text.c_str() encoding:[NSString defaultCStringEncoding]]]; + if (type == 0) + { + [alert addButtonWithTitle:@"Okay"]; + } else if (type == 1) + { + [alert addButtonWithTitle:@"Okay"]; + [alert addButtonWithTitle:@"Cancel"]; + } else if (type == 2) + { + [alert addButtonWithTitle:@"Yes"]; + [alert addButtonWithTitle:@"No"]; + } + response = [alert runModal]; } - long ret = [alert runModal]; - [alert dealloc]; - - if (ret == NSAlertFirstButtonReturn) + if (response == NSAlertFirstButtonReturn) { if (type == 1) { - ret = 3; + response = 3; } else if (type == 2) { - ret = 0; + response = 0; } - } else if (ret == NSAlertSecondButtonReturn) + } else if (response == NSAlertSecondButtonReturn) { if (type == 0 || type == 1) { - ret = 2; + response = 2; } else if (type == 2) { - ret = 1; + response = 1; } } - return ret; + return response; } @@ -445,7 +438,6 @@ unsigned int getModifiers() void updateBadge(int count) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSDockTile *tile = [[LLNSApplication sharedApplication] dockTile]; if (count > 0) { NSString *value = [NSString stringWithFormat:@"%d",count]; @@ -453,15 +445,12 @@ void updateBadge(int count) } else { [tile setBadgeLabel:nil]; } - [pool release]; } void setTitle(const std::string& title) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; LLNSWindow *winRef = [(LLAppDelegate*)[[LLNSApplication sharedApplication] delegate] window]; NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; [winRef setTitle:nsTitle]; - [pool release]; } diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 7aa00cce58..3eada9b817 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -57,12 +57,6 @@ @synthesize inputView; @synthesize currentInputLanguage; -- (void)dealloc -{ - [currentInputLanguage release]; - [super dealloc]; -} - - (void) applicationWillFinishLaunching:(NSNotification *)notification { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; @@ -157,7 +151,6 @@ return NSTerminateCancel; } else { // pumpMainLoop() returned true: it's done. Okay, done with frameTimer. - [frameTimer release]; cleanupViewer(); return NSTerminateNow; } @@ -170,7 +163,6 @@ { // Once pumpMainLoop() reports that we're done, cancel frameTimer: // stop the repetitive calls. - [frameTimer release]; [[LLNSApplication sharedApplication] terminate:self]; } } @@ -225,142 +217,7 @@ ret = false; } - [nonRomanScript release]; return ret; } -#if defined(LL_BUGSPLAT) - -- (NSString *)applicationLogForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager -{ - CrashMetadata& meta(CrashMetadata_instance()); - // As of BugsplatMac 1.0.6, userName and userEmail properties are now - // exposed by the BugsplatStartupManager. Set them here, since the - // defaultUserNameForBugsplatStartupManager and - // defaultUserEmailForBugsplatStartupManager methods are called later, for - // the *current* run, rather than for the previous crashed run whose crash - // report we are about to send. - infos("applicationLogForBugsplatStartupManager setting userName = '" + - meta.agentFullname + '"'); - bugsplatStartupManager.userName = - [NSString stringWithCString:meta.agentFullname.c_str() - encoding:NSUTF8StringEncoding]; - // Use the email field for OS version, just as we do on Windows, until - // BugSplat provides more metadata fields. - infos("applicationLogForBugsplatStartupManager setting userEmail = '" + - meta.OSInfo + '"'); - bugsplatStartupManager.userEmail = - [NSString stringWithCString:meta.OSInfo.c_str() - encoding:NSUTF8StringEncoding]; - // This strangely-named override method's return value contributes the - // User Description metadata field. - infos("applicationLogForBugsplatStartupManager -> '" + meta.fatalMessage + "'"); - return [NSString stringWithCString:meta.fatalMessage.c_str() - encoding:NSUTF8StringEncoding]; -} - -- (NSString *)applicationKeyForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager signal:(NSString *)signal exceptionName:(NSString *)exceptionName exceptionReason:(NSString *)exceptionReason { - // TODO: exceptionName, exceptionReason - - // Windows sends location within region as well, but that's because - // BugSplat for Windows intercepts crashes during the same run, and that - // information can be queried once. On the Mac, any metadata we have is - // written (and rewritten) to the static_debug_info.log file that we read - // at the start of the next viewer run. It seems ridiculously expensive to - // rewrite that file on every frame in which the avatar moves. - std::string regionName(CrashMetadata_instance().regionName); - infos("applicationKeyForBugsplatStartupManager -> '" + regionName + "'"); - return [NSString stringWithCString:regionName.c_str() - encoding:NSUTF8StringEncoding]; -} - -- (NSString *)defaultUserNameForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager { - std::string agentFullname(CrashMetadata_instance().agentFullname); - infos("defaultUserNameForBugsplatStartupManager -> '" + agentFullname + "'"); - return [NSString stringWithCString:agentFullname.c_str() - encoding:NSUTF8StringEncoding]; -} - -- (NSString *)defaultUserEmailForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager { - // Use the email field for OS version, just as we do on Windows, until - // BugSplat provides more metadata fields. - std::string OSInfo(CrashMetadata_instance().OSInfo); - infos("defaultUserEmailForBugsplatStartupManager -> '" + OSInfo + "'"); - return [NSString stringWithCString:OSInfo.c_str() - encoding:NSUTF8StringEncoding]; -} - -- (void)bugsplatStartupManagerWillSendCrashReport:(BugsplatStartupManager *)bugsplatStartupManager -{ - infos("bugsplatStartupManagerWillSendCrashReport"); -} - -struct AttachmentInfo -{ - AttachmentInfo(const std::string& path, const std::string& type): - pathname(path), - basename(boost::filesystem::path(path).filename().string()), - mimetype(type) - {} - - std::string pathname, basename, mimetype; -}; - -- (NSArray<BugsplatAttachment *> *)attachmentsForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager -{ - const CrashMetadata& metadata(CrashMetadata_instance()); - - // Since we must do very similar processing for each of several file - // pathnames, start by collecting them into a vector so we can iterate - // instead of spelling out the logic for each. - std::vector<AttachmentInfo> info{ - AttachmentInfo(metadata.logFilePathname, "text/plain"), - AttachmentInfo(metadata.userSettingsPathname, "text/xml"), - AttachmentInfo(metadata.staticDebugPathname, "text/xml") - }; - - // We "happen to know" that info[0].basename is "SecondLife.old" -- due to - // the fact that BugsplatMac only notices a crash during the viewer run - // following the crash. Replace .old with .log to reduce confusion. - info[0].basename = - boost::filesystem::path(info[0].pathname).stem().string() + ".log"; - - NSMutableArray *attachments = [[NSMutableArray alloc] init]; - - // Iterate over each AttachmentInfo in info vector - for (const AttachmentInfo& attach : info) - { - NSString *nspathname = [NSString stringWithCString:attach.pathname.c_str() - encoding:NSUTF8StringEncoding]; - NSString *nsbasename = [NSString stringWithCString:attach.basename.c_str() - encoding:NSUTF8StringEncoding]; - NSString *nsmimetype = [NSString stringWithCString:attach.mimetype.c_str() - encoding:NSUTF8StringEncoding]; - NSData *nsdata = [NSData dataWithContentsOfFile:nspathname]; - - BugsplatAttachment *attachment = - [[BugsplatAttachment alloc] initWithFilename:nsbasename - attachmentData:nsdata - contentType:nsmimetype]; - - [attachments addObject:attachment]; - infos("attachmentsForBugsplatStartupManager attaching " + attach.pathname); - } - - return attachments; -} - -- (void)bugsplatStartupManagerDidFinishSendingCrashReport:(BugsplatStartupManager *)bugsplatStartupManager -{ - infos("Sent crash report to BugSplat"); -} - -- (void)bugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager didFailWithError:(NSError *)error -{ - // TODO: message string from NSError - infos("Could not send crash report to BugSplat"); -} - -#endif // LL_BUGSPLAT - @end diff --git a/indra/newview/llappviewermacosx-objc.mm b/indra/newview/llappviewermacosx-objc.mm index 5b98172f82..8e1c9cf0eb 100644 --- a/indra/newview/llappviewermacosx-objc.mm +++ b/indra/newview/llappviewermacosx-objc.mm @@ -35,12 +35,11 @@ void launchApplication(const std::string* app_name, const std::vector<std::string>* args) { - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - if (app_name->empty()) return; - NSMutableString* app_name_ns = [NSMutableString stringWithString:[[NSBundle mainBundle] resourcePath]]; //Path to resource dir + NSMutableString* app_name_ns = [NSMutableString + stringWithString:[[NSBundle mainBundle] + resourcePath]]; //Path to resource dir [app_name_ns appendFormat:@"/%@", [NSString stringWithCString:app_name->c_str() encoding:[NSString defaultCStringEncoding]]]; @@ -56,13 +55,13 @@ void launchApplication(const std::string* app_name, const std::vector<std::strin } NSTask *task = [[NSTask alloc] init]; - NSBundle *bundle = [NSBundle bundleWithPath:[[NSWorkspace sharedWorkspace] fullPathForApplication:app_name_ns]]; + NSBundle *bundle = [NSBundle bundleWithPath:[[NSWorkspace sharedWorkspace] + fullPathForApplication:app_name_ns]]; @try { [task setLaunchPath:[bundle executablePath]]; } @catch (NSException *theException) { NSLog(@"Caught a %@ exception, bailing.", theException); - [pool release]; return; } [task setArguments:args_ns]; @@ -75,6 +74,5 @@ void launchApplication(const std::string* app_name, const std::vector<std::strin // [workspace launchApplicationAtURL:url options:0 configuration:[NSDictionary dictionaryWithObject:args_ns forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; //TODO Handle error - [pool release]; return; } diff --git a/indra/newview/lldesktopnotificationsmacosx.mm b/indra/newview/lldesktopnotificationsmacosx.mm index 3b2b3ff4a0..e636c712fe 100644 --- a/indra/newview/lldesktopnotificationsmacosx.mm +++ b/indra/newview/lldesktopnotificationsmacosx.mm @@ -38,15 +38,12 @@ void LLDesktopNotificationsMacOSX::sendNotification(const std::string& title, const std::string& body, bool play_sound) { if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_7_2) return; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = [NSString stringWithUTF8String:title.c_str()]; notification.informativeText = [NSString stringWithUTF8String:body.c_str()]; notification.soundName = play_sound ? NSUserNotificationDefaultSoundName : nil; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; - [notification release]; - [pool release]; } #endif // LL_DARWIN diff --git a/indra/newview/llfilepicker.cpp b/indra/newview/llfilepicker.cpp index b02a3c3460..184c62bff6 100644 --- a/indra/newview/llfilepicker.cpp +++ b/indra/newview/llfilepicker.cpp @@ -778,15 +778,15 @@ bool LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filena gViewerWindow->getWindow()->beforeDialog(); // Run the dialog - std::string* filev = doSaveDialog(namestring, + std::string filev = doSaveDialog(namestring, extension, mPickOptions); gViewerWindow->getWindow()->afterDialog(); - if ( filev && !filev->empty() ) + if ( !filev.empty() ) { - mFiles.push_back(*filev); + mFiles.push_back(filev); return true; } diff --git a/indra/newview/llfilepicker_mac.h b/indra/newview/llfilepicker_mac.h index 4a80c4a128..39a01e64d1 100644 --- a/indra/newview/llfilepicker_mac.h +++ b/indra/newview/llfilepicker_mac.h @@ -40,7 +40,7 @@ //void modelessPicker(); std::vector<std::string>* doLoadDialog(const std::vector<std::string> allowed_types, unsigned int flags); -std::string* doSaveDialog(const std::string& file, +std::string doSaveDialog(const std::string& file, const std::string& extension, unsigned int flags); enum { diff --git a/indra/newview/llfilepicker_mac.mm b/indra/newview/llfilepicker_mac.mm index 7d4159df67..54aa903b74 100644 --- a/indra/newview/llfilepicker_mac.mm +++ b/indra/newview/llfilepicker_mac.mm @@ -32,7 +32,6 @@ std::vector<std::string>* doLoadDialog(const std::vector<std::string> allowed_types, unsigned int flags) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSInteger result; //Aura TODO: We could init a small window and release it at the end of this routine @@ -95,16 +94,14 @@ std::vector<std::string>* doLoadDialog(const std::vector<std::string> allowed_ty outfiles->push_back(*afilestr); } } - [pool release]; return outfiles; } -std::string* doSaveDialog(const std::string& file, +std::string doSaveDialog(const std::string& file, const std::string& extension, unsigned int flags) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSSavePanel *panel = [NSSavePanel savePanel]; NSString *extensionns = [NSString stringWithCString:extension.c_str() encoding:[NSString defaultCStringEncoding]]; @@ -116,7 +113,6 @@ std::string* doSaveDialog(const std::string& file, [panel setAllowedFileTypes:fileType]; NSString *fileName = [NSString stringWithCString:file.c_str() encoding:[NSString defaultCStringEncoding]]; - std::string *outfile = NULL; NSURL* url = [NSURL fileURLWithPath:fileName]; [panel setNameFieldStringValue: fileName]; [panel setDirectoryURL: url]; @@ -124,11 +120,10 @@ std::string* doSaveDialog(const std::string& file, { NSURL* url = [panel URL]; NSString* p = [url path]; - outfile = new std::string( [p UTF8String] ); + return std::string( [p UTF8String] ); // write the file } - [pool release]; - return outfile; + return std::string(); } #endif -- GitLab