Merge pull request #7282 from zzmp/fix/tex-cache

Avoid caching textures before they load
This commit is contained in:
Seth Alves 2016-03-09 09:25:01 -08:00
commit a2eb819bc2
4 changed files with 11 additions and 4 deletions

View file

@ -344,6 +344,7 @@ void NetworkTexture::setImage(const QImage& image, void* voidTexture, int origin
_width = _height = 0;
}
_isCacheable = true;
finishedLoading(true);
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));

View file

@ -132,6 +132,8 @@ signals:
protected:
virtual bool isCacheable() const override { return _isCacheable; }
virtual void downloadFinished(const QByteArray& data) override;
Q_INVOKABLE void loadContent(const QByteArray& content);
@ -146,6 +148,7 @@ private:
int _originalHeight { 0 };
int _width { 0 };
int _height { 0 };
bool _isCacheable { false };
};
#endif // hifi_TextureCache_h

View file

@ -278,20 +278,20 @@ void Resource::refresh() {
}
void Resource::allReferencesCleared() {
if (_cache) {
if (_cache && isCacheable()) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "allReferencesCleared");
return;
}
// create and reinsert new shared pointer
QSharedPointer<Resource> self(this, &Resource::allReferencesCleared);
setSelf(self);
reinsert();
// add to the unused list
_cache->addUnusedResource(self);
} else {
delete this;
}

View file

@ -192,6 +192,9 @@ protected slots:
protected:
virtual void init();
/// Checks whether the resource is cacheable.
virtual bool isCacheable() const { return true; }
/// Called when the download has finished
virtual void downloadFinished(const QByteArray& data);