dotnet / dotnet/wpf

Hidden cursor causes freezes

Open
#2,868 0 comments 2 reactions 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: Any
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

**Problem description:**
When the cursor is hidden (`Cursor = Cursors.None`) and a application has a large heap, a lot mouse moves causes it to freeze.

**Actual behavior:**
* `Cursors.None._cursorHandle` is null ([load code](https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs#L326));
* `Cursors.None.Handle` always creates a new handle ([Cursor.Handle](https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs#L163), [GetInvalidCursor](https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsOther.cs#L321));
* `CursorSafeHandle` is counted by `HandleCollector` ([here](https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsOther.cs#L238));
* When more than [500](https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs#L6340) `CursorSafeHandle` are created, `HandleCollector` calls `GC.Collect()` ([here](https://github.com/dotnet/wpf/blob/8c7ab1592b6c70e732106aeabf58f215d4b71c22/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HandleCollector.cs#L121));
* Garbage Collection freezes all threads.

**Expected behavior:**
Cursors.None hides cursor and not causes GC.Collect

Code to reproduce: https://gist.github.com/ReeJK/a8a0e3b5569741b24311d23fe071452b

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.