summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNicolas Guichard <nicolas.guichard@kdab.com>2020-07-16 15:25:41 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-07-16 17:04:38 +0000
commit923c00c21a78dca999bf66ec3ea2888de9beee85 (patch)
tree71acd3af379062f6a01fb7a7fc173816bb9dcbb0 /src
parenta622e52d29146fe229928d398ebb50373279ae15 (diff)
rhi: fix SubmissionContext::loadShader for Unicode files
QRegularExpression::match takes a QString and not a QByteArray, so QRegularExpressionMatch::capturedStart is not reliable to locate bytes in a QByteArray which might contain Unicode data. This fixes the issue by explicitly working on QStrings. Change-Id: Ia32ee169718d98e7197d7bfa19ca23e6e243dc25 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit 13067bf7313e2e0e9c16e952bc97dd8854695967) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
index 5b217929c..1eefe645f 100644
--- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
+++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
@@ -1679,7 +1679,7 @@ void preprocessRHIShader(QVector<QByteArray> &shaderCodes)
"\\s*,\\s*std140.*)\\)\\s*uniform\\s*([a-zA-Z0-9_]+)"));
auto replaceBinding = [&bindings, &assignedBindings](
- int &offset, QRegularExpressionMatch &match, QByteArray &code,
+ int &offset, QRegularExpressionMatch &match, QString &code,
int indexCapture, int variableCapture) noexcept {
int index = match.captured(indexCapture).toInt();
QByteArray variable = match.captured(variableCapture).toUtf8();
@@ -1714,27 +1714,32 @@ void preprocessRHIShader(QVector<QByteArray> &shaderCodes)
};
for (QByteArray &shaderCode : shaderCodes) {
+ // Since QRegularExpression::match takes a QString anyway, convert once beforehand
+ QString shaderString = shaderCode;
+
// Regex for the sampler variables
int offset = 0;
- auto match = samplerRegex.match(shaderCode, offset);
+ auto match = samplerRegex.match(shaderString, offset);
while (match.hasMatch()) {
const int indexCapture = 1;
const int variableCapture = 2;
- replaceBinding(offset, match, shaderCode, indexCapture, variableCapture);
+ replaceBinding(offset, match, shaderString, indexCapture, variableCapture);
- match = samplerRegex.match(shaderCode, offset);
+ match = samplerRegex.match(shaderString, offset);
}
// Regex for the UBOs
offset = 0;
- match = uboRegex.match(shaderCode, offset);
+ match = uboRegex.match(shaderString, offset);
while (match.hasMatch()) {
const int indexCapture = !match.capturedView(1).isEmpty() ? 1 : 2;
const int variableCapture = 3;
- replaceBinding(offset, match, shaderCode, indexCapture, variableCapture);
+ replaceBinding(offset, match, shaderString, indexCapture, variableCapture);
- match = uboRegex.match(shaderCode, offset);
+ match = uboRegex.match(shaderString, offset);
}
+
+ shaderCode = shaderString.toUtf8();
}
}