Bug 29659 - Reproducible low level crash when using System.Drawing.Graphics on multiple threads at the same time
Summary: Reproducible low level crash when using System.Drawing.Graphics on multiple t...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Drawing ()
Version: 3.12.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-05-01 12:03 UTC by John Conners
Modified: 2015-05-05 10:45 UTC (History)
3 users (show)

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

A test Xamarin.Mac project that demonstrates the issue (4.30 MB, application/zip)
2015-05-01 12:03 UTC, John Conners

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 for Bug 29659 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description John Conners 2015-05-01 12:03:07 UTC
Created attachment 11025 [details]
A test Xamarin.Mac project that demonstrates the issue

I've managed to create a Xamarin.Mac project that exhibits a crash that seems to highlight that System.Drawing.Graphics is not thread safe - although it's no doubt for reasons lower down in the stack. The uncatcheable crash I get looks like this:

Assertion failed: (!"reached"), function _cairo_hash_table_lookup_exact_key, file cairo-hash.c, line 506.

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Drawing.GDIPlus.GdipDeleteGraphics (intptr) <IL 0x00025, 0xffffffff>
  at System.Drawing.Graphics.Dispose () [0x0003b] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System.Drawing/System.Drawing/Graphics.cs:304

All you need to do is run the attached project (currently running Xamarin Studio 5.8.3 with XamMac 1.12.0 and Mono and run it and virtually every time I do I get the above low level crash.

I can of course work around the problem by only using a single thread in my app but then that is somewhat less than ideal!

Apologies if this isn't actually a XamMac issue and I've misclassified it but from my point of view that's what I'm interacting with.
Comment 1 Parmendra Kumar 2015-05-01 14:05:24 UTC
I have checked this issue with attached sample and I am getting same behavior mentioned in the bug description. 

Screencast: http://www.screencast.com/t/c1BlC8L5zTg

IDELog: https://gist.github.com/Parmendrak/0e50c64dd833539aa338

Environment info:

=== Xamarin Studio ===

Version 5.9 (build 457)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
	Mono 4.0.1 ((detached/ed6b20e)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010023

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 23d069f
Branch: master
Build date: 2015-04-30 21:54:37-0400

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 509000457
Git revision: c27961c1dcfe2f8b5e5bb525c5dff33ce18a873c
Build date: 2015-04-30 19:35:14-04
Xamarin addins: df9b5918c9f7aca6da509fe3e5a62553aa101910

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 2 Chris Hamons 2015-05-05 10:45:34 UTC
This appears to be a System.Drawing / Cairo bug and not have much to do with Xamarin.Mac:

at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Drawing.GDIPlus.GdipDeleteGraphics
(intptr) <IL 0x00025, 0xffffffff>
  at System.Drawing.Graphics.Dispose () [0x0003b] in

I'm moving to the correct group in mono.