Skip to content

Uncaught Error: Element type must be nullable if array is holey in ~lib/array.ts:118:40 #2553

Closed
@kuvkir

Description

@kuvkir

I'm running into a weird issue when passing a relatively large array of objects from JS into wasm.

on the AssemblyScript side I declare the following class and a function

export class TestEntity {
  readonly id: entity.EntityId = 0;
}

export function testEntity(arr: TestEntity[]): TestEntity[] {
  for (let i = 0; i < arr.length; i++) {
    const e = arr[i];
    console.log(`#i ${i} ${e.id}`);
  }
  return arr;
}

on the JS side I run the following code, which basically creates an array of 1125 instances of TestEntity with the corresponding id (using lodash times) and passes it down to the wasm code.

      const arr = _.times(1125, id => ({ id }));
      gamelib.testEntity(arr);

I'm using the generated host bindings to pass the data.

When I use the relatively small array (a few dozens of elements) all works well. However, with large enough number of elements (e.g. 1125 in the example above), I am running into the following error message:

gamelib.debug.js:12 Uncaught Error: Element type must be nullable if array is holey in ~lib/array.ts:118:40
    at gamelib.debug.js:12:17
    at abort (gamelib.debug.js:13:10)
    at ~lib/array/Array<assembly/PlainObject/TestEntity>#__get (PlainObject.ts:128:39)
    at assembly/PlainObject/testEntity (PlainObject.ts:60:19)
    at export:assembly/PlainObject/testEntity (array.ts:121:5)
    at Object.testEntity (gamelib.debug.js:198:111)

The stack trace shows the error occurs in the array.ts [] operator ( @operator("[]") private __get(index: i32): T ).
From the error message, the wasm code complains that the array is holey, while it is definitely not. It only contains the instances of TestEntity class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions