Bug 10537

Summary: unnecessary crash in ContainerControl.SendControlFocus
Product: [Mono] Class Libraries Reporter: Stephen McConnel <stephen_mcconnel>
Component: Windows.FormsAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: eb1, masafa, mono-bugs+mono
Priority: Lowest    
Version: 2.10.x   
Target Milestone: Community   
Hardware: PC   
OS: Linux   
Tags: mono-community Is this bug a regression?: ---
Last known good build:
Attachments: FixContainerControlCrash.patch is a proposed fix for this bug.

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