The problem I am encountering involves the Store API, which presumably has some memory restrictions to prevent abuse and over-use. Previously, I used this API with success to record and display a few pages of text upon request by a character stored under a number of different keys.
However, just the other day, I tried to make a change to one of these pages of text and received an error I had never received before. I never changed the code.
wasm error: out of bounds memory access
wasm stack trace:
.~lib/string/String.UTF8.encode@varargs(i32) i32
.~lib/host/Store.setString<~lib/string/String>(i32,i32)
.../../script/setFile(i32,i32,i32)
.../../script/cmdFileSet(i32)
.../../script/onCommand(i32,i32)
The actual change to the file was a typo correction, and the total memory usage across all of the different files was <12 KB. Later tinkering revealed that this error did not occur when using Store.setString() to set a key to a value with under 512 bytes of data. Most of my files were between 2–3 KB of text.
Here are some snippets from the affected code:
@json
class objFile {
@alias("name")
name: string
@alias("content")
content: string
@alias("owner")
owner: string
constructor(name: string, content: string, owner: string) {
this.name = name
this.content = content
this.owner = owner
}
}
function setFile(name: string, content: string, owner: string): void {
const file = new objFile(name, content, owner)
Store.setString(`file.${name}`, JSON.stringify<objFile>(file))
}