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

CanvasJSSDKBindings bug fix to allow Unity project development build to succeed #311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gnoph
Copy link

@gnoph gnoph commented Aug 16, 2019

The original line translates to

Module["FBUnity"] = LibraryManager.library.$FBUnity

Which is apparently wrong. $FBUnity is a member of FBUnityLib. It should be

Module["FBUnity"] = FBUnityLib.$FBUnity

That is, the first parameter for autoAddDeps should be FBUnityLib. Function autoAddDeps is defined in DynamicJslibLoader.js found under Unity's WebGL playback engine.

Without the fix, a development build for a Unity project with this library will fail with "Unresolved symbol: rand". Release build does work. I'm not sure why.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@gnoph
Copy link
Author

gnoph commented Oct 28, 2019

Apparently Unity has two sets of mergeInto and autoAddDeps methods. One from emscripten (found in utility.js and library.js), the other is provided by Unity (DynamicJsLibLoader.js).
Emscripten version:

function mergeInto(obj, other) {
  for (var i in other) {
    obj[i] = other[i];
  }
  return obj;
}

function autoAddDeps(object, name) {
  name = [name];
  for (var item in object) {
    if (item.substr(-6) != '__deps') {
      if (!object[item + '__deps']) {
        object[item + '__deps'] = name;
      } else {
        object[item + '__deps'].push(name[0]); // add to existing list
      }
    }
  }
}

Unity version:

function mergeInto(obj, other) {
  for (var name in other) {
    Module[emscriptenFinalName(name)] = other[name];
  }
}

function autoAddDeps(object, name) {
  Module[emscriptenFinalName(name)] = object[name];
}

The Unity version is used when "use pre-built engine" is checked (or when development build is enabled as well?). With the emscripten version, it's OK to call autoAddDeps with LibraryManager.library as the first parameter. It will however cause the dependencies being added to all javascript functions from all js libraries.

According to emscripten (https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html), the first parameter for autoAddDeps is "myLibrary", which in this case should be FBUnity.

image

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

Successfully merging this pull request may close these issues.

None yet

2 participants