Thanks to visit codestin.com
Credit goes to github.com

Skip to content

System.NullReferenceException at System.Windows.Forms.Hwnd.AddInvalidArea after 10-20 minutes runtime with aggressive Control.Invalidate() calls #21806

@qrp73

Description

@qrp73

Steps to Reproduce

  1. do agressive Control.Invalidate() calls (50 frames per second) from background thread with the following OnPaint code until exception happens:
protected override void OnPaint(PaintEventArgs e)
{
    e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
    e.Graphics.DrawImage(drawImage, drawRect);
    var rect = new Rectangle(new Point(0, 0), new Size(ClientSize.Width, ClientSize.Height));
    var region = new Region(rect);
    region.Exclude(drawRect);
    e.Graphics.FillRegion(Brushes.Black, region);
}

The issue is stable reproduced, but requires to wait for a long time.

Current Behavior

After some long period (5-20 minutes) the exception System.NullReferenceException is thrown and no more window paint

Expected Behavior

Expected no exception

On which platforms did you notice this

Linux Raspberry Pi OS Bookworm (Wayland Wayfire) aarch64

$ uname -a
Linux raspi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

Version Used:

$ mono --version
Mono JIT compiler version 6.12.0.200 (tarball Tue Jul 11 21:44:02 UTC 2023)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       normal
	Notifications: epoll
	Architecture:  arm64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(610)
	Suspend:       preemptive
	GC:            sgen (concurrent by default)

Stacktrace

System.NullReferenceException: Object reference not set to an instance of an object
  at System.Windows.Forms.Hwnd.AddInvalidArea (System.Drawing.Rectangle rect) [0x0001a] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.Hwnd.AddInvalidArea (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height) [0x0000b] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.XplatUIX11.AddExpose (System.Windows.Forms.Hwnd hwnd, System.Boolean client, System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height) [0x00057] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.XplatUIX11.Invalidate (System.IntPtr handle, System.Drawing.Rectangle rc, System.Boolean clear) [0x0004a] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.XplatUI.Invalidate (System.IntPtr handle, System.Drawing.Rectangle rc, System.Boolean clear) [0x00000] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.Control.Invalidate (System.Drawing.Rectangle rc, System.Boolean invalidateChildren) [0x00041] in <25c2bdf9d79a43a599eb46bd15cd77fb>:0 
  at System.Windows.Forms.Control.Invalidate ()
  at TEST.TestControl.RequestUpdate() [0x001b6] in <61967c82b0984a6b8723cdd11864b85f>:0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions