fix crash setting model texture

(cherry picked from commit b152bf02af4eb17cf5c169ca9c577154c83901f7)
This commit is contained in:
howard-stearns 2018-06-07 11:49:56 -07:00 committed by SamGondelman
parent 1646f543cd
commit df0ecb44a8
2 changed files with 7 additions and 8 deletions

View file

@ -1074,15 +1074,11 @@ int Model::getLastFreeJointIndex(int jointIndex) const {
void Model::setTextures(const QVariantMap& textures) { void Model::setTextures(const QVariantMap& textures) {
if (isLoaded()) { if (isLoaded()) {
_needsUpdateTextures = true; _pendingTextures.clear();
_needsFixupInScene = true; _needsFixupInScene = true;
_renderGeometry->setTextures(textures); _renderGeometry->setTextures(textures);
} else { } else {
// FIXME(Huffman): Disconnect previously connected lambdas so we don't set textures multiple _pendingTextures = textures;
// after the geometry has finished loading.
connect(&_renderWatcher, &GeometryResourceWatcher::finished, this, [this, textures]() {
_renderGeometry->setTextures(textures);
});
} }
} }
@ -1106,7 +1102,8 @@ void Model::setURL(const QUrl& url) {
} }
_needsReload = true; _needsReload = true;
_needsUpdateTextures = true; // One might be tempted to _pendingTextures.clear(), thinking that a new URL means an old texture doesn't apply.
// But sometimes, particularly when first setting the values, the texture might be set first. So let's not clear here.
_visualGeometryRequestFailed = false; _visualGeometryRequestFailed = false;
_needsFixupInScene = true; _needsFixupInScene = true;
invalidCalculatedMeshBoxes(); invalidCalculatedMeshBoxes();
@ -1123,6 +1120,8 @@ void Model::setURL(const QUrl& url) {
void Model::loadURLFinished(bool success) { void Model::loadURLFinished(bool success) {
if (!success) { if (!success) {
_visualGeometryRequestFailed = true; _visualGeometryRequestFailed = true;
} else if (!_pendingTextures.empty()) {
setTextures(_pendingTextures);
} }
emit setURLFinished(success); emit setURLFinished(success);
} }

View file

@ -457,7 +457,7 @@ protected:
bool _needsFixupInScene { true }; // needs to be removed/re-added to scene bool _needsFixupInScene { true }; // needs to be removed/re-added to scene
bool _needsReload { true }; bool _needsReload { true };
bool _needsUpdateClusterMatrices { true }; bool _needsUpdateClusterMatrices { true };
mutable bool _needsUpdateTextures { true }; QVariantMap _pendingTextures { };
friend class ModelMeshPartPayload; friend class ModelMeshPartPayload;
Rig _rig; Rig _rig;