qgis / qgis-js

QGIS core ported to WebAssembly to run it on the web platform
https://qgis.github.io/qgis-js
GNU General Public License v2.0
170 stars 9 forks source link

Loading expressions throws RuntimeError #5

Closed wonder-sk closed 1 year ago

wonder-sk commented 1 year ago

When using a QGIS project containing vector tiles layer with a couple of styling rules, it failed to load with this RuntimeError:

qgis-js.wasm:0x56fcf5 Uncaught (in promise) RuntimeError: memory access out of bounds
    at QgsExpressionNodeFunction::QgsExpressionNodeFunction(int, QgsExpressionNode::NodeList*) (qgis-js.wasm:0x56fcf5)
    at exp_parse(expression_parser_context*) (qgis-js.wasm:0x54bcd8)
    at parseExpression(QString const&, QString&, QList<QgsExpression::ParserError>&) (qgis-js.wasm:0x54e28d)
    at QgsExpression::QgsExpression(QString const&) (qgis-js.wasm:0x55145b)
    at QgsProperty::loadVariant(QVariant const&) (qgis-js.wasm:0x9d9bd2)
    at QgsPropertyCollection::loadVariant(QVariant const&, QMap<int, QgsPropertyDefinition> const&) (qgis-js.wasm:0x9dfd97)
    at QgsAbstractPropertyCollection::readXml(QDomElement const&, QMap<int, QgsPropertyDefinition> const&) (qgis-js.wasm:0x9dce89)
    at QgsSymbolLayerUtils::loadSymbolLayer(QDomElement&, QgsReadWriteContext const&) (qgis-js.wasm:0x447961)
    at QgsSymbolLayerUtils::loadSymbol(QDomElement const&, QgsReadWriteContext const&) (qgis-js.wasm:0x4455a1)
    at QgsSymbolLayerUtils::loadSymbols(QDomElement&, QgsReadWriteContext const&) (qgis-js.wasm:0x45d3f7)

QgsExpressionNodeFunction tries to lock a recursive mutex, maybe that's the reason (possibly related to #3 which also fails when locking mutex, but with a different error message)

boardend commented 1 year ago

FYI: @andreasneumann hit that issue too and provided me a test project. I'm currently looking into this.

boardend commented 1 year ago

The old patch to get the QGIS expressions "working" in a debug build was way too aggressive. Basically removing all expression functions, which made the whole expression evaluation useless/failing 🙈

This is now fixed with https://github.com/qgis/qgis-js/commit/afbdda9cfee2dc288b1b9d4e17161e81ddeae978 which adds the needed flag (forcing optimization in debug builds) only to expression/qgsexpressionfunction.cpp in QGIS (see also the upstream emscripten issue). QgsExpressions are now working with all build types in Chormium/Firefox 🥳

The fix is also published to the temporary demo site. The test project form @andreasneumann seems to work fine. Please report back so we can close this issue.

andreasneumann commented 1 year ago

@boardend and @wonder-sk - looks good. I tested with my project and it loads fine.

There are a few issues with this project still (text size too small, cut-off-labels), but for these we should open separate issues.

boardend commented 1 year ago

Thanks for your feedback. See https://github.com/qgis/qgis-js/issues/8 and feel free to open a new issue for the cut-off-labels.