Skip to content

RuntimeError: memory access out of bounds #175

@feedthejim

Description

@feedthejim

hi, it's me again. I'm getting the following error without any ways of debugging (for some reason, Mozilla does't execute my code.

Uncaught (in promise) RuntimeError: memory access out of bounds
    at assembly/Vector3/Vector3#subtract (wasm-function[24]:5)
    at assembly/Sphere/Sphere#intersect (wasm-function[26]:12)
    at assembly/RayTracer/RayTracer#trace (wasm-function[32]:56)
    at assembly/RayTracer/RayTracer#render (wasm-function[33]:309)
    at assembly/index/init (wasm-function[34]:970)
    at WebAssembly.instantiateStreaming.then.module 

Here are the relevants bits of code.

Vector3.ts

  subtract(v2: Vector3): Vector3 {
    return new Vector3(this.x - v2.x, this.y - v2.y, this.z - v2.z);
  }

Sphere.ts

  intersect(rayOrigin: Vector3, rayDirection: Vector3): Intersection | null {
    let l: Vector3 = this.center.subtract(rayOrigin);
  

RayTracer.ts

     let transmission: Vector3 = new Vector3(1, 1, 1);
        let lightDirection = this.elements[i].center
          .subtract(intersectionPoint)
          .normalize();
        for (let j = 0; j < this.elements.length; j++) {
          if (i !== j) {
            let hitInfo: Intersection | null = this.elements[j].intersect(
              intersectionPoint.add(intersectionNormal.multiply(bias)),
              lightDirection,
            );
           

Any idea how I could debug my own code ? What are the best practices when using the arena allocator etc ? I haven't seen any example of using dynamic allocation on any of the projects using assemblyscript.

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