Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style "Meters at scale" hogs CPU #28690

Closed
qgib opened this issue Dec 22, 2018 · 2 comments · Fixed by #37218
Closed

Style "Meters at scale" hogs CPU #28690

qgib opened this issue Dec 22, 2018 · 2 comments · Fixed by #37218
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Symbology Related to vector layer symbology or renderers

Comments

@qgib
Copy link
Contributor

qgib commented Dec 22, 2018

Author Name: Daniel Krüger (@palstek)
Original Redmine Issue: 20871
Affected QGIS version: 3.4.2
Redmine category:symbology


After selecting "Meters at scale" option in a style QGIS becomes unresponsive for couple of seconds to several minutes. This involves at least the following situations:

  • Opening the project takes several minutes
  • Opening the layer settings which contains the "Meters at scale" option
  • Clicking on an item in the symbol tree
  • Changing an option of an item in the symbol tree

I attached gdb to a running QGIS process and pressed CTRL-C when clicking on symbol tab sheet in layer settings and the dialog got unresponsive for a minute or so. Maybe this helps a little bit.

Thread 1 "qgis.bin" received signal SIGINT, Interrupt.
0x00007fc790791fac in __sin_local (x=2.3596955266584345e-07) at ../sysdeps/ieee754/dbl-64/s_sin.c:473
473	../sysdeps/ieee754/dbl-64/s_sin.c: Datei oder Verzeichnis nicht gefunden.
(gdb) bac
#_0  0x00007fc790791fac in __sin_local (x=2.3596955266584345e-07) at ../sysdeps/ieee754/dbl-64/s_sin.c:473
#_1  0x00007fc790791fac in __sincos (x=2.3596955266584345e-07, sinx=0x7ffc5e7817b8, cosx=0x7ffc5e7817b0) at ../sysdeps/ieee754/dbl-64/s_sincos.c:75
#_2  0x00007fc79ba94d61 in QgsDistanceArea::computeSpheroidProject(QgsPointXY const&, double, double) const () at /usr/lib/libqgis_core.so.3.4.2
#_3  0x00007fc79ba9527a in QgsDistanceArea::measureLineProjected(QgsPointXY const&, double, double, QgsPointXY*) const () at /usr/lib/libqgis_core.so.3.4.2
#_4  0x00007fc79bc4459c in QgsRenderContext::convertMetersToMapUnits(double) const () at /usr/lib/libqgis_core.so.3.4.2
#_5  0x00007fc79bc44715 in QgsRenderContext::convertToPainterUnits(double, QgsUnitTypes::RenderUnit, QgsMapUnitScale const&) const () at /usr/lib/libqgis_core.so.3.4.2
#_6  0x00007fc79b8395fd in QgsMarkerSymbolLayer::markerOffset(QgsSymbolRenderContext&, double, double, QgsUnitTypes::RenderUnit, QgsUnitTypes::RenderUnit, double&, double&, QgsMapUnitScale const&, QgsMapUnitScale const&) const () at /usr/lib/libqgis_core.so.3.4.2
#_7  0x00007fc79b8397af in QgsMarkerSymbolLayer::markerOffset(QgsSymbolRenderContext&, double, double, double&, double&) const () at /usr/lib/libqgis_core.so.3.4.2
#_8  0x00007fc79b7f5c16 in QgsSimpleMarkerSymbolLayerBase::calculateOffsetAndRotation(QgsSymbolRenderContext&, double, bool&, QPointF&, double&) const () at /usr/lib/libqgis_core.so.3.4.2
#_9  0x00007fc79b7f9646 in QgsSimpleMarkerSymbolLayerBase::renderPoint(QPointF, QgsSymbolRenderContext&) () at /usr/lib/libqgis_core.so.3.4.2
#_10 0x00007fc79b7f9bfd in QgsSimpleMarkerSymbolLayer::renderPoint(QPointF, QgsSymbolRenderContext&) () at /usr/lib/libqgis_core.so.3.4.2
#_11 0x00007fc79b864b31 in QgsMarkerSymbol::renderPointUsingLayer(QgsMarkerSymbolLayer*, QPointF, QgsSymbolRenderContext&) () at /usr/lib/libqgis_core.so.3.4.2
#_12 0x00007fc79b86bb1d in QgsMarkerSymbol::renderPoint(QPointF, QgsFeature const*, QgsRenderContext&, int, bool) () at /usr/lib/libqgis_core.so.3.4.2
#_13 0x00007fc79b7e9a5d in QgsMarkerLineSymbolLayer::renderPolylineInterval(QPolygonF const&, QgsSymbolRenderContext&) () at /usr/lib/libqgis_core.so.3.4.2
#_14 0x00007fc79b7ead88 in QgsMarkerLineSymbolLayer::renderPolyline(QPolygonF const&, QgsSymbolRenderContext&) () at /usr/lib/libqgis_core.so.3.4.2
#_15 0x00007fc79b839c0e in QgsLineSymbolLayer::drawPreviewIcon(QgsSymbolRenderContext&, QSize) () at /usr/lib/libqgis_core.so.3.4.2
#_16 0x00007fc79b85ff0c in QgsSymbolLayerUtils::symbolLayerPreviewPicture(QgsSymbolLayer*, QgsUnitTypes::RenderUnit, QSize, QgsMapUnitScale const&) () at /usr/lib/libqgis_core.so.3.4.2
#_17 0x00007fc7973e9788 in QgsLayerPropertiesWidget::emitSignalChanged() () at /usr/lib/libqgis_gui.so.3.4.2
#_18 0x00007fc799f1e6cf in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#_19 0x00007fc79ad5ebe2 in QAbstractButton::toggled(bool) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_20 0x00007fc79ad5f001 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_21 0x00007fc79ad60606 in QAbstractButton::setChecked(bool) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_22 0x00007fc7973e7400 in QgsLayerPropertiesWidget::QgsLayerPropertiesWidget(QgsSymbolLayer*, QgsSymbol const*, QgsVectorLayer*, QWidget*) () at /usr/lib/libqgis_gui.so.3.4.2
#_23 0x00007fc797474255 in QgsSymbolSelectorWidget::layerChanged() () at /usr/lib/libqgis_gui.so.3.4.2
#_24 0x00007fc799f1e6cf in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#_25 0x00007fc799e9b67a in QItemSelectionModel::currentChanged(QModelIndex const&, QModelIndex const&) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#_26 0x00007fc799e9b96e in QItemSelectionModel::setCurrentIndex(QModelIndex const&, QFlags<QItemSelectionModel::SelectionFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#_27 0x00007fc79aebba4c in QAbstractItemView::mousePressEvent(QMouseEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_28 0x00007fc79af29a7b in QTreeView::mousePressEvent(QMouseEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_29 0x00007fc79acac98f in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_30 0x00007fc79ad4d4be in QFrame::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#_31 0x00007fc79aec0b3b in QAbstractItemView::viewportEvent(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5

Bug report #26289 seems to be the same. However I cannot reopen it.


@qgib
Copy link
Contributor Author

qgib commented Dec 31, 2018

Author Name: Daniel Krüger (@palstek)


I made some further debugging with Callgrind and added some qDebug() output to QgsMarkerLineSymbolLayer::renderPolylineInterval().

It seems that QgsSymbolLayerUtils::symbolLayerPreviewPicture() needs a large processing time for generating the icon. That's because it uses some default QgsRenderContext with default ellipsoid. So it draws millions of markers (repeated every 3 meters at scale) on the icon.

Where is the right place to fix this scaling issue?

If someone is interested I can provide a small test project. It takes a couple of minutes for opening the project.

@qgib
Copy link
Contributor Author

qgib commented Feb 21, 2019

Author Name: Johannes Kroeger (Johannes Kroeger)


I just ran into this option behaving weirdly and hogging CPU as well. In my case it is NOT hogging CPU when the canvas is EPSG:4326 but it is if the canvas is for example EPSG:3857 or EPSG:25832 (UTM32N).

Here is an example project, set the OTF projection to trigger the CPU hogging. You might need to pan around a bit to make it happen. Data is https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip


  • 14388 was configured as uncertain borders.qgz

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Symbology Related to vector layer symbology or renderers labels May 25, 2019
@nyalldawson nyalldawson self-assigned this Jun 15, 2020
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue Jun 16, 2020
occurring for drawing a symbol preview

Because these have no map association, certain settings like
sizes in "meters in map units" will have no meaning, and may need
special handling

Refs qgis#28690
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue Jun 16, 2020
map extent is available should fallback to a very approximate
degrees to meters conversion only

We can't do better in this situation!

Refs qgis#28690
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue Jun 16, 2020
sizes set in Meters in Map Units, because there's no map context
available to calculate these with

So, to avoid dangerously small or large sizes, when we are creating
preview images we have to just treat these sizes as mm and then clamp
them to reasonable size ranges depending on the symbol property

This fixes the quasi-hang from qgis#28690, where a marker line symbol
with interval in meters in map units caused a symbol preview
icon to be drawn with an extremely tiny interval -- resulting
in an effectively endless loop while trying to render multiple
billion markers around the edge of the symbol preview icon.

It's not ideal, but there's no better approach we can take here!

Fixes qgis#28690
nyalldawson added a commit that referenced this issue Jun 16, 2020
occurring for drawing a symbol preview

Because these have no map association, certain settings like
sizes in "meters in map units" will have no meaning, and may need
special handling

Refs #28690
nyalldawson added a commit that referenced this issue Jun 16, 2020
map extent is available should fallback to a very approximate
degrees to meters conversion only

We can't do better in this situation!

Refs #28690
nyalldawson added a commit that referenced this issue Jun 16, 2020
sizes set in Meters in Map Units, because there's no map context
available to calculate these with

So, to avoid dangerously small or large sizes, when we are creating
preview images we have to just treat these sizes as mm and then clamp
them to reasonable size ranges depending on the symbol property

This fixes the quasi-hang from #28690, where a marker line symbol
with interval in meters in map units caused a symbol preview
icon to be drawn with an extremely tiny interval -- resulting
in an effectively endless loop while trying to render multiple
billion markers around the edge of the symbol preview icon.

It's not ideal, but there's no better approach we can take here!

Fixes #28690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Symbology Related to vector layer symbology or renderers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants