Skip to content

Orphaned Decrement Error after sorting a TypedArray #1039

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

Closed
mhonert opened this issue Jan 2, 2020 · 1 comment · Fixed by #1043
Closed

Orphaned Decrement Error after sorting a TypedArray #1039

mhonert opened this issue Jan 2, 2020 · 1 comment · Fixed by #1043
Labels

Comments

@mhonert
Copy link

mhonert commented Jan 2, 2020

Hi,

I am currently writing a chess engine in AssemblyScript and for optimization purposes I wanted to replace some Arrays with TypedArrays.

Unfortunately, after the change some of my unit tests started to fail with error "An orphaned decrement has occurred...".

After some debugging, I noticed that the error seems to occur when sorting the array.
Here is a minimal code snippet to reproduce the error:

function reproduceBug(): i32 {
  let moves = new Int32Array(1);
  moves[0] = 1;
  moves.sort();
  return moves[0];
}

describe("Bug?", () => {
  it("causes error 'An orphaned decrement has occured'", () => {
    const result = reproduceBug();
    expect(result).toBe(1);
  });
})

Here is the error message when running the test with as-pect:

[Error]: Orphaned Decrement Error: An orphaned decrement has occurred at block: 4784
[Stack]:    at ~lib/rt/pure/decrement (wasm-function[54]:23)
                at ~lib/rt/pure/__release (wasm-function[55]:13)
                at assembly/__tests__/util.spec/reproduceBug (wasm-function[127]:41)
                at start:assembly/__tests__/util.spec~anonymous|5~anonymous|0 (wasm-function[129]:3)
                at node_modules/@as-pect/assembly/assembly/internal/call/__call (wasm-function[133]:7)

AssemblyScript version: 0.8.1

@MaxGraey
Copy link
Member

MaxGraey commented Jan 2, 2020

Can confirm. This happening only with Typed Arrays when size of array <= 2

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

Successfully merging a pull request may close this issue.

2 participants