[Mono-bugs] [Bug 485826] New: Constructing a Graphics object using FromHdc with a Memory DeviceContext causes crash. .NET difference

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Mar 16 19:08:51 EDT 2009


https://bugzilla.novell.com/show_bug.cgi?id=485826


           Summary: Constructing a Graphics object using FromHdc with a
                    Memory DeviceContext causes crash. .NET difference
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: i686
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: libgdiplus
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tom_hindle at sil.org
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7)
Gecko/2009030422 Ubuntu/8.04 (hardy) Firefox/3.0.7

using System;
using System.Drawing;
using System.Windows.Forms;

Following test code creates a Graphics object from a Bitmap, 
then attempts to create another Graphics object from the hdc of the first 
graphics object.


public class GraphicsTest
{    
    static void Main()
    {                        
        Bitmap b = new Bitmap(100, 100);
        Graphics mem = Graphics.FromImage(b);
        Graphics mem2 = Graphics.FromHdc(mem.GetHdc());        
    }        
}

This doesn't crash on .NET

While this may seem like a pointless thing to do, its useful if one has native
code making callbacks into managed code, and the hdc gets passed around to
allow callbacks to draw to device context which may or may not be buffered.




Reproducible: Always

Steps to Reproduce:
1. Compile and run test code
2.
3.
Actual Results:  
  at (wrapper managed-to-native) System.Drawing.GDIPlus.GdipCreateFromHDC
(intptr,intptr&) <0x00004>
  at (wrapper managed-to-native) System.Drawing.GDIPlus.GdipCreateFromHDC
(intptr,intptr&) <IL 0x00026, 0xffffffff>
  at System.Drawing.Graphics.FromHdc (intptr) [0x00000] in
/home/hindlet/src/monosvn/mcs/class/System.Drawing/System.Drawing/Graphics.cs:1674
  at GraphicsTest.Main () [0x00011] in
/home/tom/src/svn/testrepo/tom/DataGridViewTest/DataGridViewTest/DataGridViewTest.cs:13
  at (wrapper runtime-invoke) object.runtime_invoke_void
(object,intptr,intptr,intptr) <IL 0x00049, 0xffffffff>

Native stacktrace:

    /usr/local/bin/mono [0x80d73c4]
    /usr/local/bin/mono [0x80fbd71]
    [0xb7f3b440]
    /usr/lib/libgdiplus.so(GdipCreateFromHDC+0x6c) [0xb71e8a9c]
    [0xb77dbe98]
    [0xb77dbe1c]
    [0xb77d92d3]
    [0xb77d91fa]
    /usr/local/bin/mono(mono_runtime_exec_main+0xea) [0x8108cca]
    /usr/local/bin/mono(mono_runtime_run_main+0x173) [0x810a233]
    /usr/local/bin/mono(mono_main+0x16e3) [0x80b62c3]
    /usr/local/bin/mono [0x805ae11]
    /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0) [0xb7ce8450]
    /usr/local/bin/mono [0x805ad71]
Cannot access memory at address 0x0

Expected Results:  
Should not crash.

-- 
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