Editor debug view compatibility with older engine versions

Hi all,

I’m working on a project that targets a specific engine version, so we use the debug view with the use_local_engine parameter. It seems that it is no longer working for engine versions < 1.55.0. Is this a known change in compatibility of the editor? Or a bug?

In the console I see the following, which makes me suspect that the editor was updated in a way that it is not compatible with older engine versions, regarding the scenario described.

editor:loadModules (editor.method error)
sentry.js:79 TypeError: Cannot read properties of undefined (reading 'setConfig')
    at modules.js:15:31
    at Array.forEach (<anonymous>)
    at modules.js:14:21
    at e.call (editor.js:29:42)
    at e.<anonymous> (viewport.js:229:12)
    at e.<anonymous> (index.mjs:61:10)
    at e.emit (index.mjs:78:21)
    at HTMLDocument.<anonymous> (first-load.js:23:16)

The Editor only officially supports up to the last minor Engine release (in this case 1.59.X), and not any older versions. If they work, it’s because no API has changed.

Last week, the Editor started to use some API from the engine introduced about 9 months ago in 1.55, and the impact here is that engine versions older than that no longer work, as they do not support that API.

Our suggestion is to update your project to the latest versions as they get released to avoid this.

1 Like

Ok. Thanks for the info.

If you must need to use 1.54.1 or below for the short term (e.g you have a release upcoming etc) you can patch the engine to add the necessary WASM module

Example here where the patch file is set to load after the engine:
https://playcanvas.com/project/1041687/overview/roll-a-ball-1541-test

This is not recommended for the long term, just to over a near term hump.

As Martin said above, we recommend that the project is updated as soom as possible to use the current stable version.

1 Like

Thanks for this info. I noticed that the downloaded build is now causing the same error that I pasted above, from the editor. I found a different solution. I found that __modules__.js is changed, in the newer project download, and the change in that file is where the error comes from. Because that change seems meant for newer engine versions, and our project is still on an older engine version, I found that using the previously downloaded __modules__.js file resolves the issue.

Thanks again

Yes, you can do the swap of __modules__.js if that works better for you. (which has the following contents)

var loadModules = function (modules, urlPrefix, doneCallback) { // eslint-disable-line no-unused-vars

    // check for wasm module support
    function wasmSupported() {
        try {
            if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
                const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
                if (module instanceof WebAssembly.Module)
                    return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
            }
        } catch (e) { }
        return false;
    }

    // load a script
    function loadScriptAsync(url, doneCallback) {
        var tag = document.createElement('script');
        tag.onload = function () {
            doneCallback();
        };
        tag.onerror = function () {
            throw new Error('failed to load ' + url);
        };
        tag.async = true;
        tag.src = url;
        tag.crossOrigin = 'anonymous';
        document.head.appendChild(tag);
    }

    // load and initialize a wasm module
    function loadWasmModuleAsync(moduleName, jsUrl, binaryUrl, doneCallback) {
        loadScriptAsync(jsUrl, function () {
            var lib = window[moduleName];
            window[moduleName + 'Lib'] = lib;
            lib({ locateFile: function () { return binaryUrl; } } ).then( function (instance) {
                window[moduleName] = instance;
                doneCallback();
            });
        });
    }

    if (typeof modules === "undefined" || modules.length === 0) {
        // caller may depend on callback behaviour being async
        setTimeout(doneCallback);
    } else {
        var asyncCounter = modules.length;
        var asyncCallback = function () {
            asyncCounter--;
            if (asyncCounter === 0) {
                doneCallback();
            }
        };

        var wasm = wasmSupported();
        modules.forEach(function (m) {
            if (!m.hasOwnProperty('preload') || m.preload) {
                if (wasm) {
                    loadWasmModuleAsync(m.moduleName, urlPrefix + m.glueUrl, urlPrefix + m.wasmUrl, asyncCallback);
                } else {
                    if (!m.fallbackUrl) {
                        throw new Error('wasm not supported and no fallback supplied for module ' + m.moduleName);
                    }
                    loadWasmModuleAsync(m.moduleName, urlPrefix + m.fallbackUrl, "", asyncCallback);
                }
            } else {
                asyncCallback();
            }
        });
    }
};

Using the patch in the project I linked above will avoid you having to do that and also run the project in the Editor with version <1.55.0

Patch code: https://playcanvas.com/editor/code/1041687?tabs=122185623

Be sure to have it set to load after the engine

1 Like

Oh, interesting. Thanks a lot for sharing that!