Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught (in promise) cannot construct a b2Draw, no constructor in IDL #125

Open
8Observer8 opened this issue Jan 16, 2023 · 0 comments
Open

Comments

@8Observer8
Copy link

8Observer8 commented Jan 16, 2023

I try to create an instance of b2Draw class:

import { box2d } from "./init-box2d.js";

export default class DebugDrawer {
    constructor() {
        this.debugDrawer = box2d.b2Draw();
    }
}

But I have this error: Uncaught (in promise) cannot construct a b2Draw, no constructor in IDL

My example on Playground: https://plnkr.co/edit/v6CsfLVHn7Tkeg3Q

Full code of the example:

index.html

<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <canvas id="renderCanvas" width="400" height="400"></canvas>

    <!-- Since import maps are not yet supported by all browsers, it is
        necessary to add the polyfill es-module-shims.js
        Source: https://threejs.org/docs/index.html#manual/en/introduction/Installation
    -->
    <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "gl-matrix": "https://cdn.skypack.dev/[email protected]",
                "box2d": "https://dl.dropboxusercontent.com/s/08259caxtfqryce/box2d-2.3.1.min.js"
            }
        }
    </script>

    <script type="module" src="./js/main.js"></script>
</body>

</html>

js/debug-drawer.js

import { box2d } from "./init-box2d.js";

export default class DebugDrawer {
    constructor() {
        this.debugDrawer = box2d.b2Draw();
    }
}

js/init-box2d.js

import Box2DLib from "box2d";

export let box2d = null;

export function initBox2D() {
    return new Promise(resolve => {
        Box2DLib().then((re) => {
            box2d = re;
            resolve();
        });
    });
}

js/main.js

import { box2d, initBox2D } from "./init-box2d.js";
import DebugDrawer from "./debug-drawer.js";

async function init() {
    await initBox2D();

    const vec = new box2d.b2Vec2(1, 2);
    console.log(`vec = ${vec.x}, ${vec.y}`);

    const debugDrawer = new DebugDrawer();
}

init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant