4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
11.39k stars 874 forks source link

Extension func is undefined if its not called directly from a scene or behavior #1738

Open ssangervasi opened 4 years ago

ssangervasi commented 4 years ago

Describe the bug

GDevelop does not always generate the corresponding JavaScript function for an extension function. If an an extension function foo is only referenced by another extension function usesFoo, then:

  1. The events sheet for usesFoo appears fine. No error is reported while editing or during build
  2. Once the game is running, calling useFoo raises an error when it attempts to access foo. The events sheet has the name of a function it thinks should exist. In the example below, gdjs.evtsExt__FooExt__usesFoo.eventsList0x5b7538 calls gdjs.evtsExt__FooExt__foo.func which does not exist.

I've gone looking for the an issue matching this error, but as far as I can tell this hasn't been reported.

To Reproduce

Gist example: https://gist.github.com/ssangervasi/acddd389fb402af402a5f913a1e340b3

Steps to reproduce the behavior:

  1. Preview "New Scene"
  2. Press "y" or "b" to see the background change color as expected.
  3. Press "v" which should change the color to pink.
  4. See the error below.
  5. Enable either of the disabled events which reference foo/usesFoo directly from the sheet.
  6. Restart the scene.
  7. Press "v" and see that the color does change to pink.

Error:

gdjs-evtsext__fooext__usesfoo-func.js:13 Uncaught TypeError: Cannot read property 'func' of undefined
    at Object.gdjs.evtsExt__FooExt__usesFoo.eventsList0x5b7538 (gdjs-evtsext__fooext__usesfoo-func.js:13)
    at Object.gdjs.evtsExt__FooExt__usesFoo.func (gdjs-evtsext__fooext__usesfoo-func.js:53)
    at Object.gdjs.evtsExt__FooExt__UsesFooBehavior.UsesFooBehavior.usesUsesFooContext.eventsList0x5b7298 (gdjs-evtsext__fooext__usesfoobehavior.js:102)

Other details

OS: Windows 10 GD version: 5.0.0-beta92 (latest)

I also tried reproducing in the browser version using Chrome, but I couldn't even get the basic extension functions to work. I'm not worried about that case, though.

4ian commented 4 years ago

Thanks for reporting this! Thanks a lot for the very clear explanations and example file to reproduce the issue - this is appreciated :)

You're right that this is a bug. As you've seen a potential work around is to make an event that uses the extension - even if the event is never executed. Referencing any function of the extension will be enough to get the whole extension properly included.

I'll see if I can get this fixed!