question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONLoader(), callback called before uv texture image is loaded

See original GitHub issue

I have an object (exported from Blender) which is uv mapped and has a uv texture image. If I use JSONLoader() to load it , the callback function is called before the image is loaded. If I immediately try to render it in the callback, it fails. If I wait few seconds and render it, it works. This fails

var loader = new THREE.JSONLoader(true);
loader.load('Carl.js',
            function ( geometry, materials ) {
                var material = new THREE.MeshFaceMaterial( materials );
                mesh = new THREE.Mesh(geometry, material);
                scene.add(mesh);
                renderer.render(scene, camera);
            }
);

This works

var loader = new THREE.JSONLoader(true);
loader.load('Carl.js',
            function ( geometry, materials ) {
                var material = new THREE.MeshFaceMaterial( materials );
                mesh = new THREE.Mesh(geometry, material);
                scene.add(mesh);
                setTimeout(
                    function(){
                        renderer.render(scene, camera);
                    },
                    2000
                );
            }
);

I took a quick look at the source

JSONLoader calls 
    Loader.initMaterials() which calls
        Loader.createMaterial() which calls
            load_image()

load_image loads image asynchronously. Looks like JSONLoader doesn’t wait on this and calls callback function immediately.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pastinepolentacommented, Jun 5, 2016

@mrdoob any workaround? How can LoadingManager help on this ? Shall I provide a fiddle ? I can reproduce the issue with a 40kb texture on a 3G network

Read more comments on GitHub >

github_iconTop Results From Across the Web

Three.js r72 - Texture marked for update but image is ...
Texture loading is asynchronous. You need to put the bulk of your code in the loader callback. texture = THREE.ImageUtils.
Read more >
Working with Blender - Packt Hub
In this function, we specify the URL we want to load (points to the exported JSON file), a callback that is called when...
Read more >
Texture – three.js docs
An image object, typically created using the TextureLoader.load method. This can be any image (e.g., PNG, JPG, GIF, DDS) or video (e.g., MP4,...
Read more >
CS307: Texture Mapping
There are two key parts to the code: loading the image texture and mapping ... provide an anonymous callback function that calls the...
Read more >
WebGL2 Using 2 or More Textures
In this case we'll wait for all the images to load before we draw ... It creates a new Image object, sets the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found