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

RangeError when running model with a smaller amount of outputs than in a previous run #524

Closed
chrispcampbell opened this issue Aug 27, 2024 · 0 comments · Fixed by #525 or #526
Closed
Assignees

Comments

@chrispcampbell
Copy link
Contributor

While upgrading En-ROADS to work with the latest published @sdeverywhere/runtime@0.2.4 (which included some refactoring, see #471), I encountered an error in a special case:

  • model runs once with normal outputs
  • model runs a second time with a smaller subset of outputs/points

In this scenario, the wasm model will reuse a larger outputs buffer than is needed for the second run, so when storeOutputs is called, it fails when copying the array to the internal buffer because the internal view is smaller than the incoming array.

Here's the error (this is from running in NodeJS; in a browser, it may say source array is too long):

Error [RangeError]: offset is out of bounds
    at Float64Array.set (<anonymous>)
    at BufferedRunModelParams.storeOutputs ([worker eval]:3:5106)
    at BaseRunnableModel.runModel ([worker eval]:3:13145)
    at runModel ([worker eval]:3:18439)
    at [worker eval]:3:92

In the refactoring in #471, I had added a lot of tests, but in the one relevant integration test (impl-var-access), it happened to use the same number of outputs when testing both declared and impl variables, so this bug was masked.

I need to fix the storeOutputs method in BufferedRunModelParams to handle the case where the incoming array is larger than the internal view.

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