Bug 11597 - Xamarin studio randomly crash when working via rdesktop
Summary: Xamarin studio randomly crash when working via rdesktop
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: General ()
Version: 4.0.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-04-04 17:10 UTC by Sergey Mereutsa
Modified: 2013-07-16 12:46 UTC (History)
7 users (show)

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

Compressed logs from the logs directory (9.18 KB, application/octet-stream)
2013-04-05 03:03 UTC, Sergey Mereutsa
Another version of logs ... right after Xamarin Studio crashed during Remote Desktop (256.48 KB, application/octet-stream)
2013-04-19 00:12 UTC, Marcis
Reproduced (4.67 KB, text/x-log)
2013-04-19 09:36 UTC, Aleksander Morgado
Reproduced the BitBlt crash (1.09 MB, text/plain)
2013-04-30 05:40 UTC, Aleksander Morgado
10000 GDI handles (46.12 KB, image/png)
2013-05-08 05:39 UTC, Aleksander Morgado

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:

Description Sergey Mereutsa 2013-04-04 17:10:39 UTC

I noticed, that Xamarin Studio often crash (3-4-5 times per hour) when I`m working via remote desktop.

Also, code hinting results to black drop-down list until I press "down" key.

Xamarin studio works fine and never crashed when I work on the _same_ code, but when I`m working locally.

Crashes are random, I did not noticed any other details.

How can I help you to find the problem?

Regards, Serj.
Comment 1 Mikayla Hutchinson [MSFT] 2013-04-05 00:49:24 UTC
Could you attach the logs from AppData\Local\XamarinStudio-4.0\Logs?
Comment 2 Sergey Mereutsa 2013-04-05 03:03:59 UTC
Created attachment 3756 [details]
Compressed logs from the logs directory

Check the latest logs (by date) - like Ide.2013-04-05__01-05-34.log - this is when IDE crashed. 

As I see, the problem may be here:
WARNING [2013-04-05 01:06:11Z]: Gdk-Warning: gdkdrawable-win32.c:1627: BitBlt failed: The handle is invalid.
Stack trace: 
   at Gdk.Drawable.gdk_draw_pixbuf(IntPtr raw, IntPtr gc, IntPtr pixbuf, Int32 src_x, Int32 src_y, Int32 dest_x, Int32 dest_y, Int32 width, Int32 height, Int32 dither, Int32 x_dither, Int32 y_dither)
   at Gdk.Drawable.DrawPixbuf(GC gc, Pixbuf pixbuf, Int32 src_x, Int32 src_y, Int32 dest_x, Int32 dest_y, Int32 width, Int32 height, RgbDither dither, Int32 x_dither, Int32 y_dither)
   at MonoDevelop.SourceEditor.MessageBubbleTextMarker.DrawIcon(TextEditor editor, Context cr, DocumentLine line, Int32 lineNumber, Double x, Double y, Double width, Double height)
   at Mono.TextEditor.IconMargin.Draw(Context ctx, Rectangle area, DocumentLine lineSegment, Int32 line, Double x, Double y, Double lineHeight)
   at Mono.TextEditor.TextArea.RenderMargins(Context cr, Context textViewCr, Rectangle cairoRectangle)
   at Mono.TextEditor.TextArea.OnExposeEvent(EventExpose e)
   at Gtk.Widget.exposeevent_cb(IntPtr widget, IntPtr evnt)
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at MonoDevelop.Ide.IdeApp.Run()
   at MonoDevelop.Ide.IdeStartup.Run(MonoDevelopOptions options)
   at MonoDevelop.Ide.IdeStartup.Main(String[] args)
   at Xamarin.Startup.MainClass.Main(String[] args)

As I noticed, crashes happens after some "black boxes" displayed instead of the hints, but it is not possible to say exactly.
Comment 4 Marcis 2013-04-11 04:59:32 UTC

The Xamarin Studio crashed for me as well when opening a Remote Desktop connection. I attached the log: https://bugzilla.xamarin.com/attachment.cgi?id=3798
Comment 5 Aleksander Morgado 2013-04-18 14:22:46 UTC
Can anyone give me access to the log in comment #4?
Comment 6 Marcis 2013-04-19 00:12:48 UTC
Created attachment 3833 [details]
Another version of logs ... right after Xamarin Studio crashed during Remote Desktop

I could not change access details of the attachment. Therefore, I am uploading the same version a second time.

Another version of logs ... right after Xamarin Studio crashed during Remote Desktop
Comment 7 Aleksander Morgado 2013-04-19 09:36:10 UTC
Created attachment 3836 [details]

Think I just reproduced it, I was just performing a search in all files.

Last log reports:

WARNING [2013-04-19 15:19:41Z]: Gdk-Warning: gdkpixmap-win32.c:289: CreateDIBSection failed: The parameter is incorrect.
Stack trace: 
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at MonoDevelop.Ide.IdeApp.Run()
   at MonoDevelop.Ide.IdeStartup.Run(MonoDevelopOptions options)
   at MonoDevelop.Ide.IdeStartup.Main(String[] args)
   at Xamarin.Startup.MainClass.Main(String[] args)
Comment 8 Aleksander Morgado 2013-04-22 09:34:09 UTC
Marcis, your issue seems to be a completely different one, from what I can tell from your logs. Is your issue happening when launching MD? Or, after some time working with it?

Your log has tons of:
System.ArgumentOutOfRangeException: Non-negative number required.

And then ends with the following:
ERROR [2013-04-11 11:41:23Z]: An unhandled exception has occured. Terminating MonoDevelop? True
Comment 9 Marcis 2013-04-24 00:03:33 UTC
Mostly after some time working on it. I haven't seen it crash when launching MD. One or two times it crashed right after I opened the Remote Desktop connection (the Xamarin Studio was open already...), but maybe those were just coincidences.

Could it be that because I updated from Mono Develop to Xamarin Studio the update could have corrupted something? Also ... I am developing just console applications right now so I have no idea why it asks for Android SDK in the logs ...
Comment 10 Kristian Rietveld (inactive) 2013-04-26 09:36:21 UTC
What we do not know for sure is whether the warning will also trigger the application crash. From what I can see, the stack traces given so far are part of the warning. The warning fails silently and does not call abort() or something like that. The GDK code might return NULL (for example) after a failed win32 call and when not checked the NULL value could trigger a crash.

So what would be very useful here is to get a stack trace of the actual crash *combined* with any preceding warnings and the stack traces printed as part of these warning. We can then deduce whether there is a relation between the actual crash and the warnings that have been reported so far.
Comment 11 Aleksander Morgado 2013-04-29 10:15:21 UTC
For what I now can tell; a failure in e.g. CreateDIBSection() (the one I had) will result in gdk_pixmap_new() returning NULL, and that definitely triggers a crash when used within gdk/gtk, as it is always assumed that gdk_pixmap_new() doesn't fail when used internally.

So the key point here is trying to understand why CreateDIBSection() fails with ERROR_INVALID_PARAMETER, or more specifically, to understand which one is the actual invalid parameter.

From what I can see, there are two parameters that may trigger the ERROR_INVALID_PARAMETER:
 * One is the device context that we get with GetDC(). Not sure how this context can be invalid if we just got it from GetDC()...
 * The other one is the bitmap info struct that we build from the input parameters. I'm guessing that negative values for height and width could be the culprits here, although not sure yet how these could happen.
Comment 12 Aleksander Morgado 2013-04-29 12:04:04 UTC
Failures in CreateDIBSection() will actually directly assert-ing gtk; see upstream bug report and attached patch:


Still, this doesn't explain yet the CreateDIBSection() failure I've seen.
Comment 13 Aleksander Morgado 2013-04-30 05:40:57 UTC
Created attachment 3895 [details]
Reproduced the BitBlt crash

This log contains a crash with BitBlt failures, as in the original report.
Comment 14 Aleksander Morgado 2013-05-08 05:39:12 UTC
Created attachment 3931 [details]
10000 GDI handles

So, the root of the problem is clearly a leak of GDI handles, see attached screenshot with the info of the XS process when it crashes.

When the application reaches 10k GDI handles, it will end up returning errors like the ones we've seen in the logs, which ultimately make gtk+ crash badly. Other GDI leaks have been seen before in other apps, see e.g.:

This issue seems to be happening after almost 1h of having XS open via rdesktop.

We now need to see where the GDI handle is leaking...
Comment 15 Aleksander Morgado 2013-05-08 05:47:59 UTC
It is actually leaking 2 GDI handles per second when the XS window is shown in the remote desktop connection.
Comment 16 Aleksander Morgado 2013-05-08 06:27:40 UTC
This issue was just reported upstream not long ago, and is currently being fixed. There is a patch that solves the issue (I tested it with my own gtk+ build and XS), but is not yet included in gtk-2-24:

Comment 17 Mikayla Hutchinson [MSFT] 2013-07-11 20:15:41 UTC
We have prepared a new build of GTK+ that contains this fix. To test it, please download https://mjhutchinson.com/files/temp/gtk-2.24.20-2013-07-11.zip and copy the directories it contains "C:\Program Files (x86)\GtkSharp\2.12". You can verify it is installed by checking that "Help->About->Show Details" shows "GTK 2.24.20".
Comment 18 Mikayla Hutchinson [MSFT] 2013-07-16 12:46:58 UTC
The new GTK+ binaries have been included in the GTK# 2.12.22 installer, which is now in the beta update channel and will roll out to stable after we're reasonably confident there are no regressions.

Please reopen if this happens with GTK+ 2.24.20.