(Windows) Cursor hiding takes time related to number of times cursor shape has been changed since it was last hidden #68848

Closed
opened 2019-08-20 01:42:11 +02:00 by Chris Dusto · 9 comments

System Information
Operating system: Windows 7
Graphics card: AMD Radeon HD 7520G w/ nonstandard drivers

Blender Version
Broken: 2.79b, 2.79c, 2.80

Short description of error
Every time Blender changes the cursor shape under Windows, even if the cursor is already visible, it issues a call to ::ShowCursor(TRUE), which (according to MSDN) always increments an internal counter. To hide the cursor, Blender calls ::ShowCursor(FALSE) in a loop, which ends up taking O(n) time wrt the number of times the cursor's shape has changed since last being hidden. Combined with Windows doing its own stuff during the execution of the API call, this can result in a prolonged lockup. This was extremely noticable in 2.79, but is still an issue in 2.80

Exact steps for others to reproduce the error
scripting.blend This file contains a script that defines an operator, which has the effect of changing the cursor to a random shape every time a mouse move event is received, until the left mouse button is pressed. After running this operator, moving the mouse around a lot, clicking to end the operator, and then doing something that hides the mouse cursor (e.g. in 2.79, clicking within a numeric input field), Blender starts consuming 100% CPU time available to a single thread as in invokes ::ShowCursor(FALSE) in a loop.

Other notes
I had built a 2.79 using the following diff, which resolves the issue:

diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index b3a262537f..1899691116 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -775,11 +775,15 @@ void GHOST_WindowWin32::registerMouseClickEvent(int press)

 void GHOST_WindowWin32::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
 {
-       if (!visible) {
-               while (::ShowCursor(FALSE) >= 0) ;
-       }
-       else {
-               while (::ShowCursor(TRUE) < 0) ;
+       ::CURSORINFO cursorinfo;
+       cursorinfo.cbSize = sizeof(::CURSORINFO);
+       if(!(::GetCursorInfo(&cursorinfo) && (cursorinfo.flags & CURSOR_SHOWING) == (visible ? CURSOR_SHOWING : 0))) {
+               if (!visible) {
+                       while (::ShowCursor(FALSE) >= 0) ;
+               }
+               else {
+                       while (::ShowCursor(TRUE) < 0) ;
+               }
        }

        if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {```
I am currently in the process of compiling a 2.80 with the same patch applied. The additional Windows API function used should be available in all 64-bit versions of Windows (it was introduced in Windows 2000 Professional), and has the effect of completely avoiding modification of the internal counter if the cursor is already in the desired visible/hidden state.
**System Information** Operating system: Windows 7 Graphics card: AMD Radeon HD 7520G w/ nonstandard drivers **Blender Version** Broken: 2.79b, 2.79c, 2.80 **Short description of error** Every time Blender changes the cursor shape under Windows, even if the cursor is already visible, it issues a call to `::ShowCursor(TRUE)`, which (according to MSDN) always increments an internal counter. To hide the cursor, Blender calls `::ShowCursor(FALSE)` in a loop, which ends up taking O(n) time wrt the number of times the cursor's shape has changed since last being hidden. Combined with Windows doing its own stuff during the execution of the API call, this can result in a prolonged lockup. This was _extremely_ noticable in 2.79, but is still an issue in 2.80 **Exact steps for others to reproduce the error** [scripting.blend](https://archive.blender.org/developer/F7673993/scripting.blend) This file contains a script that defines an operator, which has the effect of changing the cursor to a random shape every time a mouse move event is received, until the left mouse button is pressed. After running this operator, moving the mouse around a lot, clicking to end the operator, and then doing something that hides the mouse cursor (e.g. in 2.79, clicking within a numeric input field), Blender starts consuming 100% CPU time available to a single thread as in invokes `::ShowCursor(FALSE)` in a loop. **Other notes** I had built a 2.79 using the following diff, which resolves the issue: ``` diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index b3a262537f..1899691116 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -775,11 +775,15 @@ void GHOST_WindowWin32::registerMouseClickEvent(int press) void GHOST_WindowWin32::loadCursor(bool visible, GHOST_TStandardCursor cursor) const { - if (!visible) { - while (::ShowCursor(FALSE) >= 0) ; - } - else { - while (::ShowCursor(TRUE) < 0) ; + ::CURSORINFO cursorinfo; + cursorinfo.cbSize = sizeof(::CURSORINFO); + if(!(::GetCursorInfo(&cursorinfo) && (cursorinfo.flags & CURSOR_SHOWING) == (visible ? CURSOR_SHOWING : 0))) { + if (!visible) { + while (::ShowCursor(FALSE) >= 0) ; + } + else { + while (::ShowCursor(TRUE) < 0) ; + } } if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {``` I am currently in the process of compiling a 2.80 with the same patch applied. The additional Windows API function used should be available in all 64-bit versions of Windows (it was introduced in Windows 2000 Professional), and has the effect of completely avoiding modification of the internal counter if the cursor is already in the desired visible/hidden state.
Author

Added subscriber: @TruePikachu

Added subscriber: @TruePikachu
Author

I can't 100% verify if the patch is stable under 2.80, since I have a now-unsupported-because-of-instability GPU (and I can't manage to track down the issue in the driver far enough to binary patch it), but it is stable for 2.79, and I'd expect it to remain as such for 2.80 since it doesn't touch any of Blender's own data structures.

I can't 100% **verify** if the patch is stable under 2.80, since I have a now-unsupported-because-of-instability GPU (and I can't manage to track down the issue in the driver far enough to binary patch it), but it *is* stable for 2.79, and I'd expect it to remain as such for 2.80 since it doesn't touch any of Blender's own data structures.

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

@TruePikachu I tried to reproduce (win10) issue of delay when cursor is hidden. I ran your script, moved mouse for a few minues, clicked to cancel and then clicked on numerical input.
No delay was precieved.

Is this still an issue for you?

@TruePikachu I tried to reproduce (win10) issue of delay when cursor is hidden. I ran your script, moved mouse for a few minues, clicked to cancel and then clicked on numerical input. No delay was precieved. Is this still an issue for you?
Author

Testing under Windows 7 on unpatched 2.79b, the issue still persists after system updates. I can't test right now on either Windows 10 or any 2.80 version (including dev), but I do have a new system in the mail which I should be able to run measurements on when it arrives.

Testing under Windows 7 on unpatched 2.79b, the issue still persists after system updates. I can't test *right now* on either Windows 10 or any 2.80 version (including dev), but I do have a new system in the mail which I should be able to run measurements on when it arrives.

We are trying to close as many reports as possible, so if you test this and issue is still there, you can reopen this report if closed. Or respond, that issue is still there.

We are trying to close as many reports as possible, so if you test this and issue is still there, you can reopen this report if closed. Or respond, that issue is still there.

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
Richard Antalik self-assigned this 2020-01-16 12:06:49 +01:00

Since last asking for information it has been 7 or more days, due to the policy of our bug tracker we will have to close the report.

Since last asking for information it has been 7 or more days, due to the policy of our bug tracker we will have to close the report.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#68848
No description provided.