#19238: Drawing a very long dotted or dashed line causes a crash of the entire operating system

80 views
Skip to first unread message

wxTrac

unread,
Aug 5, 2021, 7:17:18 AM8/5/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
--------------------+--------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Keywords: | Blocked By:
Blocking: | Patch: 0
--------------------+--------------------
This issue can be reproduced in the drawing sample, using the attached
patch.

'''Attention'''! Be aware that if you run the modified sample and press F3
to display the Lines screen, the entire operating system will crash or
hang (blue screen under Windows 7, total hang under Windows 10).

When drawing 1 pixel wide lines, this issue exists since wxWidgets-3.1.4
and was introduced with commit
[[https://github.com/wxWidgets/wxWidgets/commit/d245dc9e1f4e2d9416ff689b50d0650cafc5df50|d245dc9e1f4e2d9416ff689b50d0650cafc5df50]]
by using `::ExtCreatePen(PS_GEOMETRIC)` instead of `::CreatePen()` by
default for drawing dotted and dashed lines.

When drawing thicker lines (thicker than 1 pixel) the problem seems to
exist in older wxWidgets versions as well.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238>

wxTrac

unread,
Aug 5, 2021, 7:17:39 AM8/5/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------
Changes (by Dummy):

* Attachment "drawing_sample.patch" added.

wxTrac

unread,
Aug 5, 2021, 9:11:05 AM8/5/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------
Changes (by pb101):

* cc: pbfordev@… (added)


Comment:

I have just tried and did not get any Windows crash or freeze. I
experienced only a second or two long system freeze short after switching
the sample to the Lines screen.

I think the sample just becomes superslow, spending LOT of time in
`::LineTo()` when redrawing but it becomes responsive once it finishes the
drawing (takes about 50 s on my system).

wxWidgets master built as 64-bit DLL with MSVS 2019 using CMake.
Windows 10 21H1
GeForce 2060, driver version 30.0.14.7111

Obviously, this is still unacceptable but I would not be surprised if this
could be reproduced with pure Win32 code, using the same `HPEN`
properties. AFAIK, drawing with high-quality dotted and dashed pens on MSW
is known to be SLOW, see
https://docs.wxwidgets.org/trunk/pen_8h.html#aecf2ef65526d0b777114b98ecdf040ad

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:1>

wxTrac

unread,
Aug 5, 2021, 9:49:34 AM8/5/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------

Comment (by vadz):

I think this could be (video)driver-dependent. In any case, anything blue-
screening the OS can only result from a kernel-mode bug, so I don't think
wx can possibly do anything wrong here.

Unfortunately I don't see any good workaround for this neither. I.e. I can
only advise using `wxPenInfo::LowQuality()` to revert to pre-3.1.4
behaviour, but we probably still don't want to do this by default, as I
think very low quality output for short dotted lines is still a bigger
problem than this one.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:2>

wxTrac

unread,
Aug 5, 2021, 10:17:52 AM8/5/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------
Changes (by pb101):

* cc: pbfordev@… (removed)


Comment:

FWIW, here is the native Windows code reproducing the issue (superslow GDI
drawing dotted lines using geometric pens):
https://gist.github.com/PBfordev/498381e200dd402360c6c637ca8f7d64

I do not understand why Windows even bothers to "draw" the line outside
the clipbox, I would assume drawing functions were smarter than that.

As for workaround, aside from using a low quality pen, drawing seems fine
with both GDI+ and D2D. Another obvious workaround would be, if possible,
to avoid drawing unnecessarily long lines and clip the coordinates in the
user code. I understand that it is easier said than done, particularly
when even one rarely draws a single line so even a bunch of shorter ones
can take a long time...

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:3>

wxTrac

unread,
Aug 6, 2021, 3:50:38 AM8/6/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------

Comment (by Dummy):

Thanks for all of your replies.

Many thanks for testing to clarify that it is not a problem of wxWidgets.
Even if I would have preferred that, as it would have given me hope for
future improvement. :)

In my specific case, the drawing of a page bounding box (dotted rectangle
with a line width of 1 pixel) leads to the problems described if the user
zooms in very far.

Using `wxPen::SetQuality( wxPEN_QUALITY_LOW )` to revert to pre-3.1.4
behaviour is not possible, at least for now.
I don’t create the `wxPen` object myself. It is created within a library
that is used for drawing and I don't have direct access to this pen.

So for now, it seems the only way for me to revert to pre-3.1.4 behaviour
is to patch wxWidgets to change the default behaviour.
Of course, doing this will not prevent potential problems with thicker
lines.

So I think the best I can do is to limit zooming, which hopefully prevent
such problematic drawing of too long non-solid lines with
`::ExtCreatePen(PS_GEOMETRIC)` generally.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:4>

wxTrac

unread,
Aug 6, 2021, 4:38:48 AM8/6/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------
Changes (by pb101):

* cc: pbfordev@… (added)


Comment:

Replying to [comment:4 Dummy]:
> Thanks for all of your replies.
> Using `wxPen::SetQuality( wxPEN_QUALITY_LOW )` to revert to pre-3.1.4
behaviour is not possible, at least for now.
> I don’t create the `wxPen` object myself. It is created within a library
that is used for drawing and I don't have direct access to this pen.

You could use `wxDC::GetPen()` to obtain the pen copy, modify its quality,
set it to the dc, and once you are done drawing the bounding box, restore
the original pen. But I guess this is too hacky.

Perhaps there could be a static method like
`wxPen::SetDefaultPenQuality()`, which would set the default quality for
new pens to be created but I guess this would not be accepted nor that it
would help your (and similar) case.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:5>

wxTrac

unread,
Aug 6, 2021, 9:00:35 AM8/6/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------

Comment (by vadz):

We could indeed add `SetDefaultDottedPenQuality()`, but it would be a last
resort solution because it's rather ugly to have global switches like
this.

Maybe we could switch to the cosmetic pens automatically for lines longer
than 10000 pixels or something like this, if this is enough to solve the
problem?

Finally, if you can narrow down the problem to a specific driver or,
better, specific driver version, I'd consider checking for this driver on
program startup and give an error telling people about this bug and asking
them to upgrade the driver (I do something similar in my own code for ODBC
drivers -- some of them are just too buggy to be used...).

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:6>

wxTrac

unread,
Aug 10, 2021, 6:34:49 AM8/10/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-------------------
Reporter: Dummy | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------

Comment (by Dummy):

Replying to [comment:5 pb101]:
> Perhaps there could be a static method like
`wxPen::SetDefaultPenQuality()`, which would set the default quality for
new pens to be created but I guess this would not be accepted nor that it
would help your (and similar) case.

That would be a general solution that definitely would help to solve
problems like in my case.
Of course, thicker lines (> 1 pixel) would still be a potential problem
with this approach (as it always has been).
But in my case such potential problem is more a theoretical one.
Until before the update to a newer wxWidgets version, no user had
complained about such problems.
So in my case the drawing of the page bounding boxes seems to be the only
real problem in practice.


Replying to [comment:6 vadz]:
> We could indeed add `SetDefaultDottedPenQuality()`, but it would be a
last resort solution because it's rather ugly to have global switches like
this.

It's not just with dotted lines, also dashed lines. Probably with all non-
solid lines.

> Maybe we could switch to the cosmetic pens automatically for lines
longer than 10000 pixels or something like this, if this is enough to
solve the problem?

It's not just with single lines. Also with polylines, polygons,
rectangles, … maybe generally when drawing large shapes with a geometric
pens.


> Finally, if you can narrow down the problem to a specific driver or,
better, specific driver version, I'd consider checking for this driver on
program startup and give an error telling people about this bug and asking
them to upgrade the driver (I do something similar in my own code for ODBC
drivers -- some of them are just too buggy to be used...).

I don’t think it is a driver issue. Maybe the crash of Windows 7 in a
virtual machine.
But on several computers with Windows 10 (with different graphic cards and
drivers) the entire operating system hangs for one or two minutes.
Drawing large shapes with a geometric pen seems generally be horrible slow
even if only a tiny part is really visible on the screen.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:7>

wxTrac

unread,
Aug 21, 2021, 9:39:04 AM8/21/21
to wx-...@googlegroups.com
#19238: Drawing a very long dotted or dashed line causes a crash of the entire
operating system
---------------------+-----------------------
Reporter: Dummy | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone: 3.2.0
Component: wxMSW | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-----------------------
Changes (by vadz):

* status: new => confirmed
* milestone: => 3.2.0


Comment:

If we decide to do this, it should be done before 3.2.0.

It should be relatively straightforward, we'd just need to account for the
new global flag in the code in `wxPenRefData::Alloc()` in
`src/msw/pen.cpp`.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19238#comment:8>
Reply all
Reply to author
Forward
0 new messages