Skip to content

Commit d273ce6

Browse files
committed
fix lazysprite multiple callback calls
1 parent 46e57c0 commit d273ce6

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

loader/include/Geode/ui/LazySprite.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ namespace geode {
5050
bool isLoaded();
5151
bool isLoading();
5252

53-
virtual bool initWithTexture(cocos2d::CCTexture2D* texture) override;
5453
virtual bool initWithTexture(cocos2d::CCTexture2D* pTexture, const cocos2d::CCRect& rect) override;
5554
virtual bool initWithSpriteFrame(cocos2d::CCSpriteFrame* pSpriteFrame) override;
5655
virtual bool initWithSpriteFrameName(const char* pszSpriteFrameName) override;
57-
virtual bool initWithFile(const char* pszFilename) override;
5856
virtual bool initWithFile(const char* pszFilename, const cocos2d::CCRect& rect) override;
5957

6058
private:

loader/src/ui/nodes/LazySprite.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ void LazySprite::doInitFromBytes(std::vector<uint8_t> data, std::string cacheKey
298298

299299
image->release(); // deallocate the image, not needed anymore
300300
texture->release(); // bring texture's refcount back to 1
301-
302-
if (!self->initWithTexture(texture)) {
301+
302+
// this is weird but don't touch it unless you should
303+
if (!self->CCSprite::initWithTexture(texture)) {
303304
// this should never happen tbh
304305
self->onError("failed to initialize the sprite");
305306
}
@@ -323,7 +324,7 @@ CCTexture2D* LazySprite::lookupCache(char const* key) {
323324

324325
bool LazySprite::initFromCache(char const* key) {
325326
if (auto tex = this->lookupCache(key)) {
326-
return this->initWithTexture(tex);
327+
return CCSprite::initWithTexture(tex); // this will end up calling our overriden 2-arg func, which is what we want
327328
}
328329

329330
return false;
@@ -335,10 +336,6 @@ bool LazySprite::initWithTexture(CCTexture2D* texture, const CCRect& rect) {
335336
return this->postInit(CCSprite::initWithTexture(texture, rect));
336337
}
337338

338-
bool LazySprite::initWithTexture(CCTexture2D* texture) {
339-
return this->postInit(CCSprite::initWithTexture(texture));
340-
}
341-
342339
bool LazySprite::initWithSpriteFrame(CCSpriteFrame* sf) {
343340
return this->postInit(CCSprite::initWithSpriteFrame(sf));
344341
}
@@ -347,10 +344,6 @@ bool LazySprite::initWithSpriteFrameName(const char* fn) {
347344
return this->postInit(CCSprite::initWithSpriteFrameName(fn));
348345
}
349346

350-
bool LazySprite::initWithFile(const char* fn) {
351-
return this->postInit(CCSprite::initWithFile(fn));
352-
}
353-
354347
bool LazySprite::initWithFile(const char* fn, const CCRect& rect) {
355348
return this->postInit(CCSprite::initWithFile(fn, rect));
356349
}

0 commit comments

Comments
 (0)