engine icon indicating copy to clipboard operation
engine copied to clipboard

Unable to use Basis compressed textures on Facebook

Open LeXXik opened this issue 3 years ago • 18 comments

I am reporting this for visibility.

We have found that recently our games on Facebook started to lose textures. The culprit was the Basis compression. Browser successfully fetched a .basis texture. The BasisClient then composed and sent a job to web worker for transcoding. However, a worker response is never received.

I am not sure when this started. A month? A two? We initially thought it was due to client having the low network, but the issue persisted and is easily reproducible. It works fine in Launcher, though. Perhaps something to do with how Facebook configures iframes? We have disabled Basis compression for now.

Please, investigate.

LeXXik avatar Aug 03 '22 18:08 LeXXik

Did this use to work on FB at some point? If so, it would point to either a change in the engine about Basis (@slimbuck do you know if there were any major changes over the last 3 or so months?) or a change on FB side.

Is this for FB Instant games or something else?

yaustar avatar Aug 04 '22 08:08 yaustar

I am really interested to get a repro here so we can investigate

slimbuck avatar Aug 04 '22 08:08 slimbuck

Yes, it is for instant games, and was working before. I will try to make a small repro app.

LeXXik avatar Aug 04 '22 10:08 LeXXik

Any luck with the repro?

willeastcott avatar Aug 19 '22 22:08 willeastcott

@willeastcott I've made a small test app. The test app has 2 boxes - left is using non-compressed PNG texture, the right one is using Basis compression.

The PlayCanvas project that is used: https://playcanvas.com/project/972748/overview/basis-issue

I customized a bit the build to remove the loading screen. Basis issue.zip

How it looks on FB: image

I would need someone's email from developers.facebook.com, so I could add them as a tester to the app to get access to it.

LeXXik avatar Aug 23 '22 15:08 LeXXik

I've DM'ed you on Discord @LeXXik :)

yaustar avatar Aug 23 '22 15:08 yaustar

Sent a test account to @yaustar via Discord DM.

LeXXik avatar Aug 23 '22 16:08 LeXXik

Reproduced on Chrome desktop

yaustar avatar Aug 24 '22 13:08 yaustar

I've tried to use an older version of the engine (https://github.com/playcanvas/engine/releases/tag/v1.40.0) and it shows the same issue with Basis not loading

yaustar avatar Aug 24 '22 13:08 yaustar

@yaustar hmm, how are you able to change the version of the engine? FB doesn't allow external URLs. The current test app has a debug version of the latest engine inside of the ZIP file. Do you want me to upload another build with older engine version?

LeXXik avatar Aug 24 '22 13:08 LeXXik

@yaustar hmm, how are you able to change the version of the engine?

Chrome Overrides: https://blog.shahednasser.com/overrides-in-chromes-devtools/

Super useful in doing things like this where you need to proxy a file

yaustar avatar Aug 24 '22 13:08 yaustar

@LeXXik Looking at the published build on FV, it looks like window.PRELOAD_MODULES is empty when it should have the basis module config in there.

Can you link to the Editor project for this test app for me to take a closer look please?

yaustar avatar Aug 24 '22 13:08 yaustar

Yes, the link is in my message above: https://playcanvas.com/project/972748/overview/basis-issue

LeXXik avatar Aug 24 '22 13:08 LeXXik

With your FB project, did you update __settings__.js?

On FB, it looks like this:

ASSET_PREFIX = "";
SCRIPT_PREFIX = "";
SCENE_PATH = "1509328.json";
CONTEXT_OPTIONS = {
    'antialias': true,
    'alpha': false,
    'preserveDrawingBuffer': false,
    'preferWebGl2': true,
    'powerPreference': "high-performance"
};
SCRIPTS = [  ];
CONFIG_FILENAME = "config.json";
INPUT_SETTINGS = {
    useKeyboard: true,
    useMouse: true,
    useGamepads: false,
    useTouch: true
};
pc.script.legacy = false;
PRELOAD_MODULES = [
];

But with Basis in your project, it should look like:

ASSET_PREFIX = "";
SCRIPT_PREFIX = "";
SCENE_PATH = "1136674.json";
CONTEXT_OPTIONS = {
    'antialias': true,
    'alpha': false,
    'preserveDrawingBuffer': false,
    'preferWebGl2': true,
    'powerPreference': "default"
};
SCRIPTS = [ 98716180, 98716182 ];
CONFIG_FILENAME = "config.json";
INPUT_SETTINGS = {
    useKeyboard: true,
    useMouse: true,
    useGamepads: false,
    useTouch: true
};
pc.script.legacy = false;
PRELOAD_MODULES = [
    {'moduleName' : 'BASIS', 'glueUrl' : 'files/assets/99042101/1/basis.wasm.js', 'wasmUrl' : 'files/assets/99042099/1/basis.wasm.wasm', 'fallbackUrl' : 'files/assets/99042100/1/basis.js', 'preload' : false},
];

Note PRELOAD_MODULES variable. This is why the basis module is not being loaded 😅

yaustar avatar Aug 24 '22 13:08 yaustar

Ah, I might have used an settings.js from an older project, while setting up the test app. Looking into it.

LeXXik avatar Aug 24 '22 13:08 LeXXik

LeXXik updated the test app to include the Basis module and it looks like the last working version of the engine for FB Basis was: https://github.com/playcanvas/engine/releases/tag/v1.43.1

With the breaking changes in 1.44.0 where we updated the Basis worker: https://github.com/playcanvas/engine/pull/3277

The error that comes up in 1.44.0 onwards is:

image

Where it seems to be blocking loading of blob URLs

yaustar avatar Aug 24 '22 14:08 yaustar

Looks like FB Instant Games don't allow developers to define their own CSP https://support.cloudinary.com/hc/en-us/community/posts/360003923851-Can-t-load-images-in-Facebook-Instant-Games- :(

yaustar avatar Aug 24 '22 14:08 yaustar

Created a ticket on Facebook for tracking: https://developers.facebook.com/support/bugs/803565357655094/

LeXXik avatar Aug 24 '22 15:08 LeXXik

The issue is that Facebook has a server setting that forbids the use of script blobs, which fails to create a web worker. Please, consider adding an option to start Basis on main thread.

LeXXik avatar Oct 21 '22 12:10 LeXXik

Closing this in favour of a new request: https://github.com/playcanvas/engine/issues/4780

yaustar avatar Oct 21 '22 13:10 yaustar