onyx-lang / onyx

✨ The compiler and developer toolchain for Onyx
https://onyxlang.io
BSD 2-Clause "Simplified" License
576 stars 22 forks source link

browser js interop - cached dataview becomes invalidated causing load_slice_of_values, __make_func to error #152

Closed dgriffie79 closed 5 months ago

dgriffie79 commented 5 months ago

I noticed my browser applications crashing after a few minutes of running. The issue appears to be the dataview created during instantiation in Onyx.create(). If the webassembly memory is reallocated, the dataview is invalidated. It doesn't look like this is detected anywhere and the cached dataview remains invalid. In my workaround, I've replaced the use of instance.data with a new dataview at both use sites, ie:

    load_slice_of_values: function(addr, len) {
        const results = []
        const data = new DataView(this.memory.buffer)
        for (var i = 0; i < len; i++) {
            results.push(
                this.load_value(data.getBigUint64(addr + i * 8, true))
            )
        }
        return results
    },
brendanfh commented 5 months ago

Thanks for the issue! I hadn't even thought of this as a potential problem, but you are absolutely right about what is happening.