piqnt / planck.js

2D JavaScript Physics Engine
http://piqnt.com/planck.js/
MIT License
4.87k stars 236 forks source link

Script tag: Uncaught TypeError: t is null #276

Closed jes closed 4 months ago

jes commented 4 months ago

I'm trying to use the Planck+Testbed example from https://piqnt.com/planck.js/docs/install :

<html><body>
  <script src="https://cdn.jsdelivr.net/npm/planck/dist/planck-with-testbed.min.js" />
  <script>
    const { World, Testbed } = planck;
    const world = new World();

    const testbed = Testbed.mount();
    testbed.start(world);
  </script>
</body></html>

This doesn't work because closing the script tag with .../> doesn't work. So I changed that to ...></script>, and then I get:

Uncaught TypeError: t is null
    mount StageTestbed.ts:42
    <anonymous> example.html:8
StageTestbed.ts:42:2

This is Firefox 116.0.2 on Linux.

jes commented 4 months ago

OK, I've worked it out. The code in question is:

playButton.addEventListener('click', () => {
  mounted.isPaused() ? mounted.resume() : mounted.pause();
});

Preceded by:

// todo: should we create these elements if not exists?
const playButton = document.getElementById('testbed-play');

So, I guess yeah, maybe it should create these elements if not exists? Or perhaps console.log to tell people what to do. Or perhaps include them in the example HTML.

jes commented 4 months ago

Closing issue, PR is approved.