summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2020-05-19 19:53:24 +0300
committerAntti Määttä <antti.maatta@qt.io>2020-05-20 10:33:12 +0300
commit7095f9fc01ce3783c11a6a0de3eeec15ced215c8 (patch)
tree55fd3f0a5a0edfb8b8eaa8c0e9d2f036ae0c81a3
parent74a1bf8d89eb3a62e0803264cea14568e83dc690 (diff)
Properly fix editor loading custom material images
Task-number: QT3DS-4113 Change-Id: I476fc77f79149d6af3146f23679fea4b28f3c8da Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp b/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp
index 0292428..8e927fe 100644
--- a/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp
+++ b/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp
@@ -126,24 +126,29 @@ void SDynamicObject::SetStrPropertyValueT(dynamic::SPropertyDefinition &inDefini
inProjectDir = "";
if (CFileTools::RequiresCombineBaseAndRelative(inValue)) {
QString value(QDir::cleanPath(inValue));
- QDir projectDir(inProjectDir);
- QString path = projectDir.path() + QChar('/') + value;
- if (QFileInfo(path).exists()) {
- ioWorkspace.assign(path.toLatin1().constData());
- SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str()));
- // We also adjust the image path in the definition
- // I could not find a better place
- inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str());
- } else if (value.startsWith("../")) {
- path = projectDir.path() + QChar('/') + value.right(value.size() - 3);
- if (QFileInfo(path).exists()) {
- ioWorkspace.assign(path.toLatin1().constData());
- SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str()));
- // We also adjust the image path in the definition
- // I could not find a better place
- inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str());
+ QString projectDir(inProjectDir);
+ QString path = value;
+
+ bool tryResolveRelativePath = !projectDir.startsWith(QStringLiteral(":/"));
+ if (tryResolveRelativePath)
+ path.prepend(projectDir + QChar('/'));
+
+ if (tryResolveRelativePath) {
+ bool exists = QFileInfo(path).exists();
+ if (!exists && value.startsWith("../")) {
+ QString tryPath = projectDir + QChar('/') + value.right(value.size() - 3);
+ exists = QFileInfo(tryPath).exists();
+ if (exists)
+ path = tryPath;
+ else
+ path = value; // reset back to initial value if resolve failed
}
}
+ ioWorkspace.assign(path.toLatin1().constData());
+ SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str()));
+ // We also adjust the image path in the definition
+ // I could not find a better place
+ inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str());
} else {
SetPropertyValueT(inDefinition, inStrTable.RegisterStr(inValue));
// If the image path is not adjusted here, an invalid textures flashes for one frame