0

This is driving me nuts, I've tried everything for about a week. Hope some kind sole can help. I'm trying to create a new modal popup color picker. However, StopModal() keeps creating a new window.

I created a new NSWindow programatically a little like this:

class ColorPicker:NSWindow{

    void ColorPicker(IntPtr Value):base(Value){
    }

    void ColorPicker(Color StartColor){
      //Set up window here.
    }

    public void ShowModal(NSWindow NewParent){
        this.ParentWindow = NewParent;
        NSApplication.SharedApplication.RunModalForWindow(this);    
        return DialogResult;
    }
}

I create like this:

ColorPicker CP=new ColorPicker(Color.Red);

Then show it

CP.ShowDialog(MyMainWindow);

I have a button on the form that closes it and calls

NSApplication.SharedApplication.StopModal();

But for some reason this creates a second window by calling:

void ColorPicker(IntPtr Value):base(Value){
}

Then I get leak errors and soon it crashes:

NativeRelease ERROR]: type: ColorPicker handle: 137041376 count: 2 gchandle: 0

objc[350]: Object 0x103070 of class NSConcreteMapTable autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Joe McBride
  • 3,789
  • 2
  • 34
  • 38
Gordon Truslove
  • 724
  • 2
  • 10
  • 19

1 Answers1

1

This might be happening if you are not retaining a reference to the ColorPicker object in .NET. It will be garbage collected, then re-created when the Cocoa/objective-c system tries to send it a message.

Happens to me when I Dispose of the object after it closes.

Curtis
  • 1,552
  • 15
  • 20
  • Sound plausible. I am disposing the window after it closes and I have seen a couple of times messages going through sendevents to the window afterwards and screwing things up.How would I resolve this? – Gordon Truslove Jul 20 '12 at 08:25
  • Only way I found is to not dispose of the window. I haven't found any way to do it otherwise without errors.. – Curtis Jul 20 '12 at 16:16
  • That's what I've decided to do. Just store and keep reusing the same windows. Thanks for your help. – Gordon Truslove Jul 21 '12 at 08:03
  • I just don't call .Dispose(). It will be garbage collected after the objective-c releases it completely.. – Curtis Jul 21 '12 at 19:11