Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow crashes after close and reopen

I have created an NSWindow

self.storeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 800, 660) styleMask:NSWindowStyleMaskResizable|NSWindowListOrderedFrontToBack|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:false];
                             [self.storeWindow setDelegate:self];

Which opens fine and closes fine. However if I call if again of even check for nil it crashes with EXC_BAD_ACCESS.

I declare it as a string property in the header

@property (strong,nonatomic) NSWindow *storeWindow;
      if (self.storeWindow.contentView == nil) {
                            self.storeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 800, 660) styleMask:NSWindowStyleMaskResizable|NSWindowListOrderedFrontToBack|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:false];
                             [self.storeWindow setDelegate:self];
                        }
                        [self.storeWindow setBackgroundColor:[NSColor whiteColor]];
                        self.store = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 850, 640)];
                        [self.store loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:json[@"url"]]]];
                        [self.storeWindow.contentView addSubview:self.store];
                        [self.storeWindow makeKeyAndOrderFront:self.window];

Any ideas?

like image 508
mKane Avatar asked Oct 29 '25 13:10

mKane


1 Answers

NSWindow’s releasedWhenClosed property can be set to change the default behavior, which is to release a window when it is closed (unless it is owned by a window controller). The property can be set in the Interface Editor’s Attributes Inspector, or programmatically, for example:

[myWindow setReleasedWhenClosed:NO];
like image 123
red_menace Avatar answered Nov 01 '25 05:11

red_menace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!