In Cocos 3.8.2: "vb of null" Error with Tiled Sprite and Dynamic SpriteFrame

I’m facing an issue in Cocos Creator 3.8.2 when setting a Tiled Sprite dynamically at runtime. Initially, I was getting the error:

Uncaught TypeError: Cannot read property ‘vb’ of null

Issue Details:

  • I have a Sprite component with the Type set to “Tiled” and Size Mode set to “Custom”.
  • The SpriteFrame is set dynamically using a downloaded image.
  • The node’s UITransform size is set to 576x1024, but the trimmed size of the SpriteFrame is 128x128.
  • If I change the Sprite Type to “Simple”, everything works fine.
  • If I change Size Mode to “Trimmed”, it also works, but this modifies the node size, which I don’t want.

Code:

var self = this;
 cc.assetManager.loadRemote<cc.ImageAsset>(cc.native.fileUtils.getWritablePath()+savePath_ + "/" + imageName_, function (err, imageAsset) {
}
self.setTextureToSprite("image.jpg", imageAsset, self.MySprite);

Only when I used a regular function (function() {}) with ‘this’ directly, the issue was resolved:

 cc.assetManager.loadRemote<cc.ImageAsset>(cc.native.fileUtils.getWritablePath()+savePath_ + "/" + imageName_, function (err, imageAsset) {
}
this.setTextureToSprite("image.jpg", imageAsset, this.MySprite);

Why does self = this; cause an issue in Cocos 3.8.2 when using a Tiled Sprite?
Why does this issue occur only with a “Tiled” Sprite and “Custom” Size Mode, but not with “Simple” or “Trimmed”?
Why do we commonly use var self = this; in Cocos TypeScript? Is it still necessary in newer Cocos versions?

@Tom_k

2D Renderable Components Batching Guidelines | Cocos Creator, Please increase the value of BATCHER2D_MEM_INCREMENT under Project → Project Settings → Macro Configurations for a try.

Thanks for the suggestion! I increased BATCHER2D_MEM_INCREMENT from 144 to 1000, but the issue still persists.

Interestingly, I initially used var self = this; inside my callback function (as was common in Cocos 2.4.7), but it caused the “vb of null” error in Cocos 3.8.2. However, when I directly used this to call the function, everything worked fine!

This is the opposite of what I expected, since self = this; was previously used to retain context in callbacks. Has something changed in how Cocos 3.8.2 handles this scope? Should we avoid self = this; now?

Would appreciate any insights!
@Tom_k