Can't set texture for spriteframe

i’m using cocos creator 3.7.0
i wrote a little code to load asset texture from resource.

var tex = Array(25).fill(new Texture2D());
        for(let j = 0; j < 25; j++){
            let url = "image/item48-"+j.toString()+"/texture";
              resources.load(url,Texture2D,null,(e, s)=>{
                tex[j] = s;
            });
        }
        console.log(tex);

then create node and set sriteframe texture from tex array

for(let i = 0; i< this.col; i ++)
        {
          for(let j = 0; j < this.row; j++){
            if(this.val[i][j] != 0 ){
              let l = new Node;
              this.node.insertChild(l,cnt);
              this.label[i][j] = l.addComponent(Sprite);
              const sf = new SpriteFrame();
              sf.texture = tex[0];
              this.label[i][j].spriteFrame = sf;
              l.setPosition(this.start_X + this.width*(i+1/2), this.start_y + this.height*(j+1/2));
              cnt ++;
            }
          }

when run it show error : debug.ts:103 Sampler binding ‘cc_spriteTexture’ at set 2 binding 12 index 0 is not bounded
how fix it ?
Sorry for my english!

hello ,bro.
first, I recommend you to follow the TS style when you are coding, that will make your code easy to read.
for example, use let instead of var.

from your code, I guess you want to load some text images and cache them to an array, then you use them to create the spriteFrames when needed.

if you are encountering Sampler binding ‘cc_spriteTexture’ at set 2 binding 12 index 0 is not bounded

one of the possible reasons may be the textures don’t load completely.
resources.load is an async method, it will take time to finish.

if you call your second code segment right after the first one, the tex have 25 Texture2D items but without initialized. the error comes out.

to solve this. you can do it like this:

let loadedCnt = 0;
let tex = Array(25).fill(new Texture2D());
for(let j = 0; j < 25; j++){
    let url = "image/item48-"+j.toString()+"/texture";
      resources.load(url,Texture2D,null,(e, s)=>{
        tex[j] = s;
        loadedCnt++;
        if(loadedCnt >= 25){
              //it's here ,you can use the tex array.
              // e.g. call the method to setup your label sprites.
        }
    });
}
console.log(tex);

Hope it can help.

btw, it’s better to choose Cocos Creator for your question. because you are asking the question about Cocos Creator 3.7.0, ahahahaha.

best regards! my bro!