Commit 9f2c9e67 authored by Sean McBride's avatar Sean McBride
Browse files

BUG: fixed bug 8934, various memory management errors in cocoa code

parent 338530be
......@@ -23,7 +23,7 @@ PURPOSE. See the above copyright notice for more information.
#include <vtksys/ios/sstream>
vtkCxxRevisionMacro(vtkCocoaRenderWindow, "1.65");
vtkCxxRevisionMacro(vtkCocoaRenderWindow, "1.66");
vtkStandardNewMacro(vtkCocoaRenderWindow);
......@@ -38,6 +38,7 @@ vtkCocoaRenderWindow::vtkCocoaRenderWindow()
// init the ivar to null first.
this->CocoaManager = NULL;
this->SetCocoaManager(reinterpret_cast<void *>(cocoaManager));
[cocoaManager self]; // prevent premature collection.
this->WindowCreated = 0;
this->ViewCreated = 0;
......@@ -517,23 +518,22 @@ void vtkCocoaRenderWindow::CreateAWindow()
(CGFloat)this->Size[0] / this->ScaleFactor,
(CGFloat)this->Size[1] / this->ScaleFactor);
NSWindow* theWindow = [[NSWindow alloc]
NSWindow* theWindow = [[[NSWindow alloc]
initWithContentRect:ctRect
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
defer:NO] autorelease];
if (!theWindow)
{
vtkErrorMacro("Could not create window, serious error!");
return;
}
[theWindow makeKeyAndOrderFront:nil];
[theWindow setAcceptsMouseMovedEvents:YES];
this->SetWindowId(theWindow);
this->WindowCreated = 1;
[theWindow makeKeyAndOrderFront:nil];
[theWindow setAcceptsMouseMovedEvents:YES];
}
// Always use the scaling factor from the window once it is created.
......@@ -632,6 +632,9 @@ void vtkCocoaRenderWindow::CreateGLContext()
this->SetPixelFormat((void*)pixelFormat);
this->SetContextId((void*)context);
[pixelFormat self]; // prevent premature collection.
[context self]; // prevent premature collection.
}
//----------------------------------------------------------------------------
......@@ -714,9 +717,13 @@ int *vtkCocoaRenderWindow::GetSize()
// is overloaded. It's really the NSView that vtk draws into, so we
// return its size.
// VTK measures in pixels, but NSWindow/NSView measure in points; convert.
NSRect frameRect = [(NSView*)this->GetDisplayId() frame];
this->Size[0] = (int)round(NSWidth(frameRect) * this->ScaleFactor);
this->Size[1] = (int)round(NSHeight(frameRect) * this->ScaleFactor);
NSView* view = (NSView*)this->GetDisplayId();
if (view)
{
NSRect frameRect = [view frame];
this->Size[0] = (int)round(NSWidth(frameRect) * this->ScaleFactor);
this->Size[1] = (int)round(NSHeight(frameRect) * this->ScaleFactor);
}
return this->Superclass::GetSize();
}
......@@ -756,9 +763,13 @@ int *vtkCocoaRenderWindow::GetPosition()
// is overloaded. In this case, it's the position of the NSWindow itself
// on the screen that we return. We don't much care where the NSView is
// within the NSWindow.
NSRect winFrameRect = [(NSWindow*)this->GetWindowId() frame];
this->Position[0] = (int)NSMinX(winFrameRect);
this->Position[1] = (int)NSMinY(winFrameRect);
NSWindow* window = (NSWindow*)this->GetWindowId();
if (window)
{
NSRect winFrameRect = [window frame];
this->Position[0] = (int)NSMinX(winFrameRect);
this->Position[1] = (int)NSMinY(winFrameRect);
}
return this->Position;
}
......
......@@ -21,7 +21,7 @@
#import <OpenGL/gl.h>
//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkCocoaRenderWindowInteractor, "1.26");
vtkCxxRevisionMacro(vtkCocoaRenderWindowInteractor, "1.27");
vtkStandardNewMacro(vtkCocoaRenderWindowInteractor);
//----------------------------------------------------------------------------
......@@ -97,7 +97,7 @@ class vtkEarlyCocoaSetup
// We create a global/static instance of this class to ensure that we have an
// autorelease pool before main() starts (the C++ constructor for a global
// object runs before main). Note: I am unable to find a place to delete this
// object safely.
// object safely, but having it around for the lifetime of the process is ok.
static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
//----------------------------------------------------------------------------
......@@ -209,25 +209,17 @@ static vtkEarlyCocoaSetup * gEarlyCocoaSetup = new vtkEarlyCocoaSetup();
{
win = reinterpret_cast<NSWindow *>(renWin->GetWindowId());
// We don't want to be informed of every window closing, so check for nil.
// We don't want to be informed of every window closing, so check for nil.
if (win != nil)
{
{
// Register for the windowWillClose notification in order to stop
// the run loop if the window closes.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(windowWillClose:)
name:@"NSWindowWillCloseNotification"
object:win];
}
}
}
// Now that we are about to begin the standard Cocoa event loop, we can get
// rid of the 'pool of last resort' because [NSApp run] will create a new
// pool for every event
#ifndef __OBJC_GC__
delete gEarlyCocoaSetup;
gEarlyCocoaSetup = 0;
#endif
// Start the NSApplication's run loop
[NSApp run];
......@@ -297,8 +289,11 @@ vtkCocoaRenderWindowInteractor::vtkCocoaRenderWindowInteractor()
// init the ivar to null first.
this->CocoaManager = NULL;
this->SetCocoaManager(reinterpret_cast<void *>(cocoaManager));
[cocoaManager self]; // prevent premature collection.
this->SetTimerDictionary(reinterpret_cast<void *>([NSMutableDictionary dictionary]));
NSMutableDictionary* timerDictionary = [NSMutableDictionary dictionary];
this->SetTimerDictionary(reinterpret_cast<void *>(timerDictionary));
[timerDictionary self]; // prevent premature collection.
}
//----------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment