Bug 60673 - NSWindowGraphicsContext object 0x604000a26060 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
Summary: NSWindowGraphicsContext object 0x604000a26060 overreleased while already deal...
Status: RESOLVED UPSTREAM
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Runtime ()
Version: 4.0 (d15-5)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-14 14:48 UTC by Alain
Modified: 2017-11-17 17:02 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
App Problem (418.32 KB, application/zip)
2017-11-14 14:48 UTC, Alain
Details
Repro in obj-c with no Xamarin code (110.61 KB, application/zip)
2017-11-16 16:41 UTC, Chris Hamons
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Alain 2017-11-14 14:48:49 UTC
Created attachment 25698 [details]
App Problem

Hi,

I have a problem that I have for months with Xamarin.mac with the following error:

Process:               AppProblem [25443]
Path:                  /Users/USER/*/AppProblem.app/Contents/MacOS/AppProblem
Identifier:            com.companyname.AppProblem
Version:               1.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           AppProblem [25443]
User ID:               501

Date/Time:             2017-11-14 15:33:01.659 +0100
OS Version:            Mac OS X 10.13.1 (17B48)
Report Version:        12
Bridge OS Version:     3.0 (14Y661)
Anonymous UUID:        39D1A757-0570-E03A-A31B-3B35E752DDAA

Sleep/Wake UUID:       9CB3476D-2997-4AB2-AD71-029EE75B0E1D

Time Awake Since Boot: 250000 seconds
Time Since Wake:       23000 seconds

System Integrity Protection: enabled

Crashed Thread:        52  Dispatch queue: NSOperationQueue 0x604000a3db60 (QOS: UNSPECIFIED)

Exception Type:        EXC_BAD_INSTRUCTION (SIGABRT)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
objc[25443]: NSWindowGraphicsContext object 0x604000a26060 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x604000a332c0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x604000a34740 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c34ce0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c34ce0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x604000a2ecc0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c34ea0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c326c0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x604000a34480 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x604000a33fc0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c32320 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c31a80 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
objc[25443]: NSWindowGraphicsContext object 0x600000c296e0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
abort() called
BUG IN CLIENT OF LIBPLATFORM: Trying to recursively lock an os_unfair_lock


I made a small program to reproduce the error. Can you tell me what to do to solve this?

To reproduce the error, click on the button "Problem", a window is displayed. You click on the "Pas. diabète" button. A new View is displayed, click on the "Annuler" button. Repeat the operation 4, 5 times and it crash with the error reported above.

Same with the button "Prétrajet diabète".



Is there anything I do not do well in the code?

Thank you for your help.


Alain



=== Visual Studio Community 2017 for Mac (Preview) ===

Version 7.3 Preview (7.3 build 740)
Installation UUID: af98516b-7b3c-413e-ba1b-95a1baeaccc6
Runtime:
	Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010007

=== NuGet ===

Version : 4.3.1.4445

=== .NET Core ===

Runtime : /usr/local/share/dotnet/dotnet
Version du runtime : 2.0.0
SDK : /usr/local/share/dotnet/sdk/2.0.0/Sdks
Version du SDK : 2.0.0
SDK MSBuild : /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version : 1.6.0
Emplacement : /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version : 8.1.0.22 (Visual Studio Community)
Android SDK: /Users/macbookrogister/Library/Developer/Xamarin/android-sdk-macosx
	Versions Android prises en charge :
		6.0(Niveau d’API 23)
		7.1(Niveau d’API 25)

Version des outils du SDK : 25.2.5
Version des outils de plateforme du SDK : 25.0.5
Version des outils de génération du SDK : 25.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Code EPL d'Android Designer disponible ici :
https://github.com/xamarin/AndroidDesigner.EPL

=== Apple Developer Tools ===

Xcode 9.1 (13532)
Build 9B55

=== Xamarin.iOS ===

Version: 11.4.0.214 (Visual Studio Community)
Hash: c4240f3f
Branch: d15-5
Build date: 2017-11-08 17:28:18-0500

=== Xamarin.Mac ===

Version: 4.0.0.214 (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 703000740
Git revision: e627d44dfa30d44a55f9a5f67daf10ba11236e96
Build date: 2017-10-27 17:26:45-04
Xamarin addins: a1e6d0fb5813ae35c96027955d4909ffc259b94b
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.13.1
Darwin 17.2.0 Darwin Kernel Version 17.2.0
    Fri Sep 29 18:27:05 PDT 2017
    root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
Comment 1 Alain 2017-11-16 08:21:41 UTC
News for this problem ?
Comment 2 Chris Hamons 2017-11-16 15:33:20 UTC
I've spent some time stripping away nearly every single bit of C# code from this sample and can still make it reproduce.

I'm writing a tiny obj-c sample using the nibs, because I strongly suspect this is turning into a Radar.
Comment 3 Chris Hamons 2017-11-16 16:41:47 UTC
Created attachment 25741 [details]
Repro in obj-c with no Xamarin code
Comment 4 Chris Hamons 2017-11-16 17:07:40 UTC
I have been able to reproduce the crash multiple times using the obj-c sample attached.

This is thus a Cocoa bug and not a Xamarin bug (there is no C# / XM in the attached).

A few interesting but not confirmed suspicions. 

- I have been unable to reproduce it on my 10.12 machine but can on my 10.13. I am uncertain if it is because my 10.13 machine is slower or different macOS versions.
- My original obj-c sample did not use a modal window and did not reproduce. So possibly related to modal event loops?
- Sometimes clicking away or clicking the buttons makes it reproduce more quickly.

This feels _very_ similar to a radar I previous filed, 99% certain for you:

27567455 - Rapid window creation with presentViewControllerAsModalWindow and closing can cause crash

In any case, consider filing a radar at bugreport.apple.com and possibly reference the older radar.

Since it is crashing inside Cocoa, there is nothing that can be done in Xamarin.Mac. I would consider:

- Simplifying your applications UI by bisecting your UI, maybe some component is causing Cocoa to bug out
- Refactor your UI workflow to not use rapidly open/closed modal dialogs

but working around Apple's bugs is never fun. :(
Comment 5 Alain 2017-11-16 17:44:01 UTC
Chris,

since I'm on MacOS high Sierra, this bug is very present and arrives very quickly. It seems to me that on Sierra arrived but much less quickly. Now, it's no longer possible to work like that.

Compared to your comment, I changed my entire application to display only one modal window and switch views in it. It was much more stable.

To reproduce the problem, I voluntarily put a view that contained a lot of labels but you should know that even if the views contain much less, after a while, I have the same problem.

The suggestion that you propose to me is therefore not possible.

I made a program that changed the views in the main window and not in a modal window and it never crashed. Can you try that in your Objective-C application and tell me if that's the case?

Thank you

Alain
Comment 6 Chris Hamons 2017-11-16 17:49:36 UTC
I've attached my obj-c example so you can easily modify it, but yes, when I previous added the nib's views directly to the window and not to a modal window it did not crash in my limited testing.

Unfortunately, I can't provide much help beyond that, as this is not my bug. I do not have access to AppKit source code to debug this.

Consider filing a radar with apple:

http://bugreport.apple.com/

You can also consider filing a TSIs here:

https://developer.apple.com/support/technical/

Best of Luck.
Comment 7 Alain 2017-11-16 18:13:08 UTC
Just a note, here we open a modal window and switch between views in this window. it must not be done quickly necessarily. If you take your time, you have the same problem ;-)

Compared to your remark that it works in the main window, I need your help.

The idea that I have is not to use a modal window but to display all the views in the main window. The problem I have is that I used toolbar (in the example, benefitWindow) to display in the modal window.

How can I switch in the main window to another window?

In other words, in the example I sent you, how to get BenefitWindow in the main window? If you can help me on that, could I go that way to get around the bug?

Thank you

Alain
Comment 8 Chris Hamons 2017-11-16 19:21:53 UTC
If you want to swap the content out of a window and replace with another, I would do something like this:

- Have multiple NSViewControllers, each holding onto one chunk of view hierarchy you want
- When you want to swap, have the current view controller do View.RemoveFromSuperview and then have the new controller's View added via  Window.ContentView.AddSubView

but that isn't normally the UI workflow Apple's HIG recommends (though it should work).

It's a reasonably basic dynamic view hierarchy change. If you have too much trouble, create a forum post and I'll drop a simple sample.
Comment 9 Alain 2017-11-17 16:12:49 UTC
Chris,

I created a single window that I called like this :

[Register("AppDelegate")]
    public class AppDelegate : NSApplicationDelegate
    {

        PrestationWindowController vuePrestation;
        public AppDelegate()
        {
            
        }

        public override void DidFinishLaunching(NSNotification notification)
        {
            // Insert code here to initialize your application

            vuePrestation = new PrestationWindowController();
            vuePrestation.Window.ReleasedWhenClosed = false;

            vuePrestation.Window.Title = "Prestation";
            vuePrestation.Window.Center();

            vuePrestation.Window.MakeKeyAndOrderFront(this);
        }

        public override void WillTerminate(NSNotification notification)
        {
            // Insert code here to tear down your application
        }
    }


And even when I do that, it crashes after a few times.

I do not understand ! I'm sure that on the MainWindow, I had already done that on SIERRA and I had no problem.
Comment 10 Chris Hamons 2017-11-17 16:14:01 UTC
@Alain - This is not the appropriate location for such questions. Please consider filing a post on the forums or stack overflow describing what you want to accomplish.
Comment 11 Alain 2017-11-17 16:50:15 UTC
Chris,

I will make a small application and I will explain what I would like to do to work around the bug.

I will post this on the forum.

Can not I send you this directly by explaining what I want to do ?

Alain
Comment 12 Alain 2017-11-17 16:59:37 UTC
When I take the application I sent you. I want on the main window switcher from one view to the other (pass from PassportDiabete to CareTravel) and vice versa without it crashing.

I can not do it either, at home, it also crash while I'm not in a modal window.

I can not imagine that such a big bug exists at APPLE. You imagine that we can not go from one view to another. it is not possible ...
Comment 13 Chris Hamons 2017-11-17 17:02:36 UTC
As the obj-c sample I posted literally contains zero Xamarin code and still crashes, it can not be a Xamarin bug. Full Stop.

As I pointed out, multiple times before, bugzilla is not a private support channel. Please stop spamming this bug.

There are multiple public locations (forums, stack overflow) that you can use instead.

I will not be responding to this bug report again.