History

fix crash setting model texture

(cherry picked from commit b152bf02af4eb17cf5c169ca9c577154c83901f7)

howard-stearns committed 8 years ago

Commit df0ecb41 parent 1646f542 files · +7 −8Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 2 files). Show all

Unified · Split

libraries/render-utils/src/Model.cpp+6−7
@@ -1074,15 +1074,11 @@ int Model::getLastFreeJointIndex(int jointIndex) const { · 1073 unmodified lines
10741074
10751075 void Model::setTextures(const QVariantMap& textures) {
10761076 if (isLoaded()) {
1077− _needsUpdateTextures = true;
1077+ _pendingTextures.clear();
10781078 _needsFixupInScene = true;
10791079 _renderGeometry->setTextures(textures);
10801080 } else {
1081− // FIXME(Huffman): Disconnect previously connected lambdas so we don't set textures multiple
1082− // after the geometry has finished loading.
1083− connect(&_renderWatcher, &GeometryResourceWatcher::finished, this, [this, textures]() {
1084− _renderGeometry->setTextures(textures);
1085− });
1081+ _pendingTextures = textures;
10861082 }
10871083 }
10881084
@@ -1106,7 +1102,8 @@ void Model::setURL(const QUrl& url) { · 17 unmodified lines
11061102 }
11071103
11081104 _needsReload = true;
1109− _needsUpdateTextures = true;
1105+ // One might be tempted to _pendingTextures.clear(), thinking that a new URL means an old texture doesn't apply.
1106+ // But sometimes, particularly when first setting the values, the texture might be set first. So let's not clear here.
11101107 _visualGeometryRequestFailed = false;
11111108 _needsFixupInScene = true;
11121109 invalidCalculatedMeshBoxes();
@@ -1123,6 +1120,8 @@ void Model::setURL(const QUrl& url) { · 10 unmodified lines
11231120 void Model::loadURLFinished(bool success) {
11241121 if (!success) {
11251122 _visualGeometryRequestFailed = true;
1123+ } else if (!_pendingTextures.empty()) {
1124+ setTextures(_pendingTextures);
11261125 }
11271126 emit setURLFinished(success);
11281127 }