Bug 10537 - unnecessary crash in ContainerControl.SendControlFocus
Summary: unnecessary crash in ContainerControl.SendControlFocus
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 2.10.x
Hardware: PC Linux
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-02-21 11:29 UTC by Stephen McConnel
Modified: 2017-09-01 12:15 UTC (History)
3 users (show)

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


Attachments
FixContainerControlCrash.patch is a proposed fix for this bug. (578 bytes, patch)
2013-02-21 11:29 UTC, Stephen McConnel
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 GitHub or Developer Community 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 FIXED

Description Stephen McConnel 2013-02-21 11:29:46 UTC
Created attachment 3444 [details]
FixContainerControlCrash.patch is a proposed fix for this bug.

I don't know how to reproduce this in a simple program, but I'm getting a consistent crash with the following stack trace:

Msg: Object reference not set to an instance of an object 
Source: System.Windows.Forms 
Assembly: System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
Stack: at System.Windows.Forms.ContainerControl.SendControlFocus (System.Windows.Forms.Control c) [0x00000] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs:325 
  at System.Windows.Forms.ContainerControl.set_ActiveControl (System.Windows.Forms.Control value) [0x0028a] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs:208 
  at System.Windows.Forms.Control.Select (Boolean directed, Boolean forward) [0x00019] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:4644 
  at System.Windows.Forms.Control.WmLButtonDown (System.Windows.Forms.Message& m) [0x00035] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5311 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00183] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5036 
  at System.Windows.Forms.ButtonBase.WndProc (System.Windows.Forms.Message& m) [0x00054] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ButtonBase.cs:632 
  at System.Windows.Forms.Button.WndProc (System.Windows.Forms.Message& m) [0x00000] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs:142 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:228 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:209 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x0008e] in /home/steve/fwrepo/mono/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs:243 
Thread: Main thread 
Thread UI culture: en 
Exception: System.NullReferenceException 

Looking at the code, it appears quite possible for active_control to be set to null in some circumstances.  Thus a simple check for null should be appropriate.  I'm attaching a proposed fix.
Comment 1 eb1 2014-03-14 07:10:07 UTC
Suggested fix in PR #955
Comment 2 eb1 2014-04-08 02:09:07 UTC
Pull request/fix merged in 6f677fd8c383e2517740a23f196625b3056cb714 on master branch