Load remote image and display it

Hi guys, I want to load remote image and display it in my game. I have refer intro to the following instructions Asset Loading · Cocos Creator.

And, I got the content about, then create Texture2D, SpriteFrame and set spriteFrame for node. But I got an error:

Uncaught TypeError: WebGLRenderingContext.texSubImage2D: Argument 7 is not valid for any of the 7-argument overloads.

Here my code:

async start () {
        let assetManager = new AssetManager();
        let remoteUrl = "http://***/image/favicon.jpeg";
        let self = this;
        assetManager.loadRemote<ImageAsset>(remoteUrl, function (err, imageAsset) {
            const spriteFrame = new SpriteFrame();
            const texture = new Texture2D();
            texture.image = imageAsset;
            spriteFrame.texture = texture;
        
            self.node.getComponent(Sprite).spriteFrame = spriteFrame;
        });
    }

Do you have solution fix it? Please help me, thank you.

I can ask engineering to have a look.

What version of Creator are you using? The doc you referenced is 3.1, is that the version you are using?

Yes, I’m using version 3.3.1.

I try to use you code to test, but not reappear the same bug like you, could your offer us a demo?

Sorry for inconvenience. It’s my company’s project, so I can’t make it public.
About details. I created a Node, set any default spriteFrame. And the script file, I will load the remote image (any) then when the response returns I will reset the spriteFrame.

Ok, did you reappear without you company’s project? If reappear, sent it to me.

1 Like

I tested it on version 3.3.1 and there is no way to reproduce your problem.
Also, there are three issues I need to point out for you.

  • 1 The assetManager in the code is already a global singleton, you don’t need to create it, you can import it by import { assetManager } from ‘cc’; and you can use it directly.
  • 2 Before start, you need to remove async, is there any special usage on your side?
  • 3 In the callback function of loadRemote, it would be better to do a null call for the err case.

Of course, I can provide a demo of my test, you can test it.


NewProject_2.zip (23.8 KB)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.