Using AssetsManager with NullEngine to load textures

It seemed to me like a bug, but may as well be a feature request :slight_smile:

Please check the PG.
If I use AssetsManager to load a texture when using NullEngine, I expect that onTaskSuccess callback would return task object, that would contain texture instance in task.texture, just the same as when using normal Engine.

Unfortunately, in that case task.texture is undefined.

I assume this happens because NullEngine.prototype.createTexture (source) calls onLoad callback immediately, so new texture does not have time to be assigned to the task (source).

Would it make sense for NullEngine to call onLoad callback with some artificial asynchronicity?

Thanks!

It is not a bug. The NullEngine is supposed to run in Node / server / no head environment where there is no DOM or image tag to load images.

If you need to create real textures, you have to use the real engine :frowning:

You’re correct, and we use NullEngine only in our unit tests (in Node). The case I described is from one of the tests. Also, I don’t need to create a real texture, I just want it to be some texture-like object, which properties I could check inside the test case.

I’ll try to elaborate my problem, here’s a rough idea of what my code does:

const assetsManager = new AssetsManager(scene);
assetsManager.onTaskSuccess = (task) => {
    // ...
    task.texture.level = 0.5;
};

When I try to test this code with NullEngine, line task.texture.level = 0.5; throws an error, because at that point task.texture is undefined. task.texture only gets defined on the very next runtime tick, so for example this code would work:

assetsManager.onTaskSuccess = (task) => {
    // ...
    setTimeout(() => { task.texture.level = 0.5; });
};

Again, this is only a problem for our unit tests, in which we use the NullEngine.

can you repro it in the PG? or in jsFiddle? this is something I should be able to fix

Even better, do you want to send a PR to fix it ? :slight_smile:

Sure, the PG link in my first message has an expected vs. actual result that can be seen in browser dev tools console.

I’ve also made another PG that has a loadTexture function that does basic texture loading, and a “test” function runTest that simulates a check against loadTexture (sorry, I failed to simulate it with an actual test runner). It should output "Texture has been applied to material: true", but currently it’s false (can also be seen in browser dev tools console).

Can do a PR of what I assume the possible fix could be, but a bit later :upside_down_face:

Go for the PR then :slight_smile: thanks!

1 Like

hi again, here’s the PR:

1 Like