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

Cannot read properties of undefined (reading 'trackedWrites') #20

Open
marionebl opened this issue May 3, 2022 · 4 comments
Open

Cannot read properties of undefined (reading 'trackedWrites') #20

marionebl opened this issue May 3, 2022 · 4 comments

Comments

@marionebl
Copy link
Contributor

I'm seeing an exception thrown from becsy source via exception tracking that I haven't been able to reproduce locally yet

Error: Cannot read properties of undefined (reading 'trackedWrites')
  at UR.write(/~/setup.js:6:5065)
  # cut

If traced it to this piece of minified code (formatted for legibility)

class UR{
  constructor(t){
    z(this,"__registry");
    z(this,"__id");
    z(this,"__valid",!0);
    this.__registry=t
  }
 /* more methods */
  write(t){
    return t.__binding.trackedWrites && this.__registry.trackWrite(this.__id,t),t.__bind(this.__id,!0)
  }
 /* more methods */
}

Scanning the source I think this mirrors
https://github.com/LastOliveGames/becsy/blob/main/src/entity.ts#L232-L240

The code I execute right before this amounts to

execute() {
    this.entities.current.forEach((entity) => {
      const a = entity.write(AComponent);
      const b = entity.write(BComponent);
      const c = entity.read(Component).property;

      b.propertyA = b.propertyA * 2
      b.propertyB =  b.propertyB * 2

      a.propertyA = somethingA;
      a.propertyB = somethingB;
    });
}

Sorry I don't have a better reproduction, I figured bringing it up might help with gathering more context by having your in-depth expertise.

@pkaminski
Copy link
Collaborator

I agree with your assessment that the exception originates in Entity.write, due to __binding being undefined. There are only two ways this could happen:

  • The component type was left out of the world's defs, so it was never initialized. Presumably that's not the issue or the repro would be trivial.
  • You called World.terminate then tried to execute another frame. It might be worth trying some scenarios around this locally.

I also just realized that the promise returned from World.terminate can actually resolve before the world has terminated when called in the middle of a frame. Is it possible this is messing you up somehow?

If none of this helps, you might want to insert an extra check into your execute method above to see if one of the component types' __binding properties is undefined, and if so capture a message with details. It might give us a further hint as to what's going on.

@marionebl
Copy link
Contributor Author

If none of this helps, you might want to insert an extra check into your execute method above to see if one of the component types' __binding properties is undefined, and if so capture a message with details. It might give us a further hint as to what's going on.

I'll do that, thanks for the suggestion! Any properties you'd be interested in specifically?

@pkaminski
Copy link
Collaborator

Any properties you'd be interested in specifically?

The type name, the id, and whether any of __bind, __allocate, and __free are set.

@pkaminski
Copy link
Collaborator

Ping -- was this issue resolved?

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

2 participants