[Mono-bugs] [Bug 386450] New: new Font() is not a new object ... sometimes
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sat May 3 17:44:36 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=386450
Summary: new Font() is not a new object ... sometimes
Product: Mono: Class Libraries
Version: 1.9.0
Platform: Other
URL: http://limada.sourceforge.net/Limaki/
OS/Version: Windows XP
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Windows.Forms
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: lytico at users.sourceforge.net
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Creating a Font-Object with new Font(...) and
disposing this font-object
disposes other "instances" of a font-object with same font-family, size and
style.
Example (tested on .Net 2.0: works; mono 1.9.0 on winXP: error; NOT tested
under linux):
public class FontProblem:Form {
TextBox editor = null;
public void testFont(){
// make a new Font:
Font fontA = new Font(
SystemFonts.DefaultFont.Name,
SystemFonts.DefaultFont.Size,
SystemFonts.DefaultFont.Style);
// make another new font with same name, size, style
using (Font fontB =
new Font(
fontA.Name,
fontA.Size,
fontA.Style)) {
// do something with the font:
editor.Font = fontB;
editor.Text = "testing";
editor.Visible = true;
editor.Focus();
Application.DoEvents();
editor.Visible = false;
// fontB is no longer in use!
editor.Font = fontA;
} // fontB is disposed
// you get the Exception here:
editor.Visible = true;
editor.Focus();
}
// stuff to have a test environment:
Button button = null;
public FontProblem() {
this.SuspendLayout();
button = new Button();
button.Name = "button";
button.Text = "Test Font";
button.Click +=
delegate(object sender, EventArgs e) { testFont(); };
this.Controls.Add(button);
editor = new TextBox();
editor.Name = "TextBox";
editor.Location = button.Location+
new Size(button.Width+5,editor.Location.Y);
this.Controls.Add(editor);
this.ResumeLayout();
}
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FontProblem());
}
}
running this program you'll get an error like this:
Unhandled Exception: System.ArgumentException: A null reference or invalid
value
was found [GDI+ status: InvalidParameter]
at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status) [0x0009d] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\System.Drawing\System.Drawing\gdipFunctions.cs:219
at System.Drawing.Font.GetHeight (single) [0x0000f] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\System.Drawing\System.Drawing\Font.cs:678
at System.Drawing.Font.GetHeight () [0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\System.Drawing\System.Drawing\Font.cs:562
at System.Drawing.Font.get_Height () [0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\System.Drawing\System.Drawing\Font.cs:428
at (wrapper remoting-invoke-with-check) System.Drawing.Font.get_Height ()
<0x00036>
at System.Windows.Forms.LineTag.MaxHeight () [0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\LineTag.cs:560
at System.Windows.Forms.Line.RecalculateLine
(System.Drawing.Graphics,System.Windows.Forms.Document) [0x0024c] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Line.cs:534
at System.Windows.Forms.Document.RecalculateDocument
(System.Drawing.Graphics,int,int,bool) [0x000ad] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\TextControl.cs:3514
at System.Windows.Forms.Document.RecalculateDocument (System.Drawing.Graphics)
[0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\TextControl.cs:3462
at System.Windows.Forms.Document.owner_VisibleChanged
(object,System.EventArgs)[0x00010] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\TextControl.cs:3597
at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs) [0x0002d]
in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:6447
at System.Windows.Forms.Control.SetVisibleCore (bool) [0x000f0] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:4944
at System.Windows.Forms.Control.set_Visible (bool) [0x0000c] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-1.9\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:3372
at (wrapper remoting-invoke-with-check)
System.Windows.Forms.Control.set_Visible (bool) <0x0004b>
at MonoWinformTests.FontProblem.testFont () <0x0018e>
..
I guess there is a font-cache somethere, the new Font() gives an object out of
this cache, so I don't get a new instance (despite of new), but a new reference
on an existing object.
cheers,
lytico
on trying to get limada.sourceforge.net/Limaki to run on mono
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list