首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Graphics.DrawLine,AccessViolation,Visual

Graphics.DrawLine,AccessViolation,Visual
EN

Stack Overflow用户
提问于 2013-08-15 02:03:11
回答 1查看 1.1K关注 0票数 1

在Graphics.DrawLine创建访问冲突时遇到困难。尝试重新启动to 2010/计算机,修复框架,更新窗口,并查找要删除的任何类型的修补程序或补丁。似乎没有什么能摆脱它。即使是MS站点上的示例也会因错误而崩溃。不知道该找什么来解决这个问题。它曾经起作用,所以我打赌这是个不好的补丁,只是不确定是哪一个。目前在windows下运行。

更新1:更新代码以与API交叉引用。DrawLineInt使用框架,DrawLineInt2使用API命令。它们都违反了DrawLine函数。将此示例放入VB6并不会造成此问题。

更新2:显然,如果VS studio环境设置设置为C++,则不会发生此错误。重置设置并将其放回"Visual“将导致此错误再次出现。卸载/安装VS2010和.NET框架并不能解决这个问题。运行构建的可执行文件不会导致可执行文件中的崩溃,但是可以使VS...hmmm..?

更新3:尝试了其他绘图方法,并在下面添加了一个调用跟踪。显然,任何使用钢笔的方法都会导致异常,但使用笔刷的方法则不会。在copy_32方法中跟踪时,指向绘制空间的指针无效( 0x0或0xBAADF00D)。这也使GroupBox无用,因为它使用相同的绘图例程。

样本代码..。

代码语言:javascript
运行
复制
Public Class Form1
Public Sub DrawLineInt2(ByVal e As PaintEventArgs)
    'Misc
    Dim Ret As GpStatus

    ' Create pen. 
    Dim blackPen As IntPtr = IntPtr.Zero
    Dim blackbrush As IntPtr = IntPtr.Zero
    Dim c As Int32 = &HFF000000

    Ret = GdipCreateSolidFill(c, blackbrush)
    'Ret = GdipCreatePen1(c, 10, GpUnit.UnitPixel, blackPen)
    Ret = GdipCreatePen2(blackbrush, 10, GpUnit.UnitPixel, blackPen)

    ' Create coordinates of points that define line. 
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim x2 As Integer = 500
    Dim y2 As Integer = 125

    ' Draw line to screen.
    Dim graphics As IntPtr = IntPtr.Zero

    'Ret = GdipCreateFromHDC(e.Graphics.GetHdc, graphics)
    Ret = GdipCreateFromHWND(Me.Handle, graphics)

    'System.AccessViolationException here
    Ret = GdipDrawLineI(graphics, blackPen, x1, y1, x2, y2)

    'Here Also
    'Ret = GdipDrawRectangleI(graphics, blackPen, x1, y1, x2, y2)

    'Here as well
    'Ret = GdipDrawArcI(graphics, blackPen, x1, y1, x2, y2, 15, 20)

    'No problems with this line
    'Ret = GdipFillRectangleI(graphics, blackbrush, x1, y1, x2, y2)


    Ret = GdipDeletePen(blackPen)
    Ret = GdipDeleteBrush(blackbrush)
    Ret = GdipDeleteGraphics(graphics)

    'e.Graphics.ReleaseHdc()
End Sub

Public Sub DrawLineInt(ByVal e As PaintEventArgs)
    ' Create pen. 
    Dim blackPen As New Pen(Color.Black, 3)
    ' Create coordinates of points that define line. 
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim x2 As Integer = 500
    Dim y2 As Integer = 100

    ' Draw line to screen.
    Try
        e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
    Catch
    End Try
    blackPen.Dispose()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    'DrawLineInt(e)
    DrawLineInt2(e)
End Sub


Private Enum GpStatus As Int32
    Ok = 0
    GenericError = 1
    InvalidParameter = 2
    OutOfMemory = 3
    ObjectBusy = 4
    InsufficientBuffer = 5
    NotImplemented = 6
    Win32Error = 7
    WrongState = 8
    Aborted = 9
    FileNotFound = 10
    ValueOverflow = 11
    AccessDenied = 12
    UnknownImageFormat = 13
    FontFamilyNotFound = 14
    FontStyleNotFound = 15
    NotTrueTypeFont = 16
    UnsupportedGdiplusVersion = 17
    GdiplusNotInitialized = 18
    PropertyNotFound = 19
    PropertyNotSupported = 20
End Enum

Private Enum GpUnit As Int32  ' aka Unit
    UnitWorld      ' 0 -- World coordinate (non-physical unit)
    UnitDisplay    ' 1 -- Variable -- for PageTransform only
    UnitPixel      ' 2 -- Each unit is one device pixel.
    UnitPoint      ' 3 -- Each unit is a printer's point, or 1/72 inch.
    UnitInch       ' 4 -- Each unit is 1 inch.
    UnitDocument   ' 5 -- Each unit is 1/300 inch.
    UnitMillimeter ' 6 -- Each unit is 1 millimeter.
End Enum

Private Declare Function GdipDrawLine Lib "gdiplus.dll" (ByVal graphics As IntPtr, ByVal pen As IntPtr, ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single) As GpStatus
Private Declare Function GdipDrawLineI Lib "gdiplus.dll" (ByVal graphics As IntPtr, ByVal pen As IntPtr, ByVal x1 As Int32, ByVal y1 As Int32, ByVal x2 As Int32, ByVal y2 As Int32) As GpStatus

Private Declare Function GdipCreatePen1 Lib "gdiplus.dll" (ByVal color As Int32, ByVal Width As Single, ByVal unit As GpUnit, ByRef pen As IntPtr) As GpStatus
Private Declare Function GdipCreatePen2 Lib "gdiplus.dll" (ByVal brush As IntPtr, ByVal Width As Single, ByVal unit As GpUnit, ByRef pen As IntPtr) As GpStatus
Private Declare Function GdipDeletePen Lib "gdiplus.dll" (ByVal pen As Int32) As GpStatus

Private Declare Function GdipCreateSolidFill Lib "gdiplus" (ByVal argb As Int32, ByRef brush As IntPtr) As GpStatus
Private Declare Function GdipDeleteBrush Lib "gdiplus" (ByVal brush As IntPtr) As GpStatus

Private Declare Function GdipFillRectangleI Lib "gdiplus" (ByVal graphics As IntPtr, ByVal brush As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal Width As Int32, ByVal Height As Int32) As GpStatus
Private Declare Function GdipDrawRectangleI Lib "gdiplus" (ByVal graphics As IntPtr, ByVal pen As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal Width As Int32, ByVal Height As Int32) As GpStatus

Private Declare Function GdipDrawArcI Lib "gdiplus" (ByVal graphics As IntPtr, ByVal pen As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal Width As Int32, ByVal Height As Int32, ByVal startAngle As Single, ByVal sweepAngle As Single) As GpStatus


Private Declare Function GdipCreateFromHDC Lib "gdiplus.dll" (ByVal hdc As IntPtr, ByRef graphics As IntPtr) As GpStatus
Private Declare Function GdipCreateFromHWND Lib "gdiplus.dll" (ByVal hwnd As IntPtr, ByRef graphics As IntPtr) As GpStatus
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As IntPtr) As GpStatus

端级

异常调用堆栈

GdiPlus.dll!ScanOperation::Copy_32() + 0x14字节 GdiPlus.dll!EpAlphaBlender::Blend() + 0x58字节 GdiPlus.dll!EpScanGdiDci::DrawScanRecords_Dci() + 0x1de字节 GdiPlus.dll!EpScanGdiDci::ProcessBatch_Dci() + 0x181字节GdiPlus.dll!EpScanGdiDci::EmptyBatch() + 0x6b5ab字节GdiPlus.dll! GdiPlus.dll!EpScanBufferNative::~EpScanBufferNative() + 0x18字节 GdiPlus.dll!DpDriver::StrokePath() + 0x20a字节 GdiPlus.dll!DriverMulti::StrokePath() + 0x6c字节GdiPlus.dll!GpGraphics::DrvStrokePath() + 0x2a字节 GdiPlus.dll!GpGraphics::RenderDrawPath() + 0xa3字节 GdiPlus.dll!GpGraphics::DrawLines() + 0xe8字节 GdiPlus.dll!GpGraphics::DrawLine() + 0x45字节 GdiPlus.dll!_GdipDrawLine@24() + 0x8e字节 GdiPlus.dll!_GdipDrawLineI@24() + 0x37字节 外部代码WindowsApplication2.exe!WindowsApplication2.Form1.DrawLineInt2(System.Windows.Forms.PaintEventArgs e)行30 + 0x17字节

例外会下降..。

System.AccessViolationException未处理Message=Attempted以读取或写入受保护的内存。这通常表明其他内存已损坏。System.Drawing.SafeNativeMethods.Gdip.GdipDrawLineI(HandleRef图形、HandleRef笔、Int32 x1、Int32 y1、Int32 x2、Int32 y2在C:\Documents和Settings\FF\Application Data\临时项目WindowsApplication1 1\Form1.vb:在C:\Documents和Settings\Local\Application Data\临时项目WindowsApplication1 1\Form1.vb:在C:\Documents和Settings\FF\Local \Application Data\临时项目WindowsApplication1 1\Form1.vb:第15行(对象发送者,第15行)在C:\Documents和Settings\FF\Local \Application Data\临时项目\WindowsApplication1 1\Form1.vb: System.Windows.Forms.Control.OnPaint(PaintEventArgs e的第19行( System.Windows.Forms.Form.OnPaint(PaintEventArgs e) )在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e处,Int16层)在System.Windows.Forms.Control.WmPaint(Message& m) 在System.Windows.Forms.ScrollableControl.WndProc(Message& m( System.Windows.Forms.Control.WndProc(Message& m) ) at System.Windows.Forms.Form.WndProc(Message& m)在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) ( System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32原因,Int32 pvLoopData在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文)在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,( Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) 17d14f5c-A 337-4978-8281-53493378c1071.vb: System.AppDomain._nExecuteAssembly(RuntimeAssembly组装处第81行,String[] Args) at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence,( Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) )在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态)在System.Threading.ThreadHelper.ThreadStart()

EN

回答 1

Stack Overflow用户

发布于 2013-08-24 00:40:29

找到了对我有用的解决方案。升级或回滚视频驱动程序。

我有一个Radeon HD6950的驱动版本9.00.100.10。当我将驱动程序回滚到8.980.0.0版时。"gdipdrawline“错误停止。这意味着现在使用该函数的所有控件都可以工作。我可以确认使用GroupBox和DataGridView,因为它们以前使用相同或类似的调用堆栈崩溃。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18245212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档