I have some code for showing a window…
- (IBAction)displayWindow:(id)sender
{
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 50, 50) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[window setBackgroundColor:[NSColor blackColor]];
[window setAlphaValue:.5];
[window setLevel:kShadyWindowLevel];
[window setReleasedWhenClosed:YES];
[window makeKeyAndOrderFront:self];
self.window = window;
}
And to close window….
- (IBAction)closeWindow:(id)sender
{
[self.window close];
}
and window is defined as a strong property…
@property (strong) NSWindow *window;
The code works the first time but when showing the window a second time the line…
self.window = window;
crashes with EXC_BAD_ACCESS…
what am i doing wrong?
Thanks in advance….
You set “releasedWhenClosed to YES in your code. Change that to NO, and it should work fine.