Casey Primozic’s Notes

Misc. notes, code, and other content I want to post publicly that don’t warrant a full blog post

By Casey Primozic

Subscribe to RSS

Compiling the Boundary-First-Flattening Library to Wasm

Here is an account of the process I developed to get the boundary-first-flattening library building for use on the web via WebAssembly.

Boundary First Flattening (I refer to it as BFF throughout this article) is a powerful algorithm and library for “surface parameterization” - or projecting 3D surfaces into 2D. It also includes built-in support for other parts of a full UV unwrapping pipeline like bin-packing texture islands into a square. I was using it for my Geotoy project - a browser-based, Shadertoy-inspired web app for procedural geometry.

Read more →

Fixing Google Chrome Using Wrong GPU on Linux

Well, here’s another chapter in the saga of graphics and GPU issues with Google Chrome on Linux.

I have a 7900 XTX GPU, and I think at least part of these issues are a result of AMD GPU drivers being pretty messed up on Linux.

The Problem

One day after updating my packages and rebooting my system, WebGL web apps were running at very low FPS in my Google Chrome browser. It was really slow - like sub-10 FPS when I usually get 165.

Read more →

Fixing Sveltekit fetch error ERR_SSL_WRONG_VERSION_NUMBER with NGINX reverse proxy

The Problem

I am using SvelteKit and importing a WebAssembly module on the server side inside a +page.server.ts file like this:

const WasmPromise = import('src/viz/wasmComp/geoscript_repl').then(
  async (engine) => {
    await engine.default(fetch('/geoscript_repl_bg.wasm'));
    return engine;
  }
);

It works when I run for local development, but it fails when running on my VPS in production. Some notes about my deployment environment:

  • I’m Sveltekit’s adapter-node
  • I’m deploying the Sveltekit app inside Docker behind an NGINX reverse proxy

This Wasm module as built using wasm-bindgen for Rust, and it needs the path to the Wasm to be explicitly provided since it’s running on the server side rather than the client.

Read more →

Fixing ltree syntax error in Postgres 15

The Problem

I was recently working with some Postgres tables that have an ltree column. I had written tests for my new feature that made use of them and all the tests passed locally.

However, the tests were failing in CI with a vague error:

ERROR: ltree syntax error at character 9 (SQLSTATE 42601)

The query that was producing this error was quite simple as well:

INSERT INTO "my_table" ("path","value") VALUES ('22e8f4e1-437f-448b-a8fb-0d7fbed8de7a','foo')

In this case, the path column was of type ltree. Running that exact query locally worked fine and I was confused as to why it wasn’t working in CI.

Read more →

Fixing Google Chrome WebGL Low Frame Rate After Turning Monitors Off on Linux

The Problem

I have two monitors: my main one at 165hz and a side monitor at 60hz. When I first boot up my computer, I’m able to run web-based games and visualizations at full 165hz on my main monitor.

However, after I turn my monitors off for the night and then get back on the next morning, all my WebGL-based applications are locked to 60 FPS or lower (and they feel stuttery and generally worse than even what I’d expect from stable 60 FPS)

Read more →

Fixing WHEA_UNCORRECTABLE_ERROR Bluescreen with Windows + Linux Dual Boot

The Problem

I dual-boot multiple Linux installs along with Windows. At some point, possibly coinciding with an update to one of my Linux installs, my Windows partition failed to boot with a bluescreen error showing a WHEA_UNCORRECTABLE_ERROR error message. I tried booting multiple times with no success.

Most info I found online about this error seemed to indicate that it was related to hardware issues, but I hadn’t made any hardware changes recently and my Linux installs continued to boot and work fine.

Read more →

Getting Kinematic Object Movement Interpolation Working in Bullet Physics/ammo.js

Background

I’m working on a browser-based game engine that uses Three.JS for rendering and a WebAssembly port of the Bullet physics engine called ammo.js for its physics engine and character controller.

Bullet is a very old physics engine and Ammo.JS is more or less a direct copy of it with a few changes to support usage in the browser. There are a lot of rough edges and things you have to figure out yourself in order to use it.

Read more →

Creating Constrained Bezier Curves for an Envelope Generator

I recently finished some work involving constrained bezier curves for use in my browser-based digital audio workstation. Specifically, I used them in its envelope generator, which looks like this:

A screenshot of the envelope generator for web synth showing the bezier curves used to define the curves that are joined together to produce the transfer function.

The circles are draggable handles that allow the user to create whatever shape they desire for the envelope. The green handles define the start and end point of each curve segment and the blue circles control its shape/steepness.

Read more →

Fixing Rust+WebAssembly Memory Access Out of Bounds Errors in Debug Mode

The Problem

In my project built with Rust compiled to WebAssembly, I started seeing errors like this that caused a crash - but only when it was compiled in debug mode:

wavetable.wasm-011dbbd6:0x17b89 Uncaught RuntimeError: memory access out of bounds
    at wavetable.wasm._ZN9wavetable2fm7effects14EffectInstance10from_parts17h321e4433e1216e56E (wavetable.wasm-011dbbd6:0x17b89)
    at wavetable.wasm._ZN9wavetable2fm7effects11EffectChain10set_effect17h969349e414104e9eE (wavetable.wasm-011dbbd6:0x1ba60)
    at wavetable.wasm.fm_synth_set_effect (wavetable.wasm-011dbbd6:0x314d3)
    at FMSynthAWP.port.onmessage (FMSynthAWP.js:171:37)

When compiling in release mode, the code ran just fine.

The decompiled debug-mode Wasm at the point of the crash looked like this:

Read more →

Fixing Cypress Tests Failing with 404 Errors in Github Actions CI but Working Locally

I have some very basic Cypress tests set up for one of my personal projects - a single-page application created with React. I have some simple Github Actions configured to automatically run those tests every time I push to the repository.

At some point somewhat randomly, those tests started failing in CI. It was probably due to some dependency getting upgraded or a change in the environment in which Github Actions runs. The tests still ran fine locally when using the same commands and configuration, though, and I struggled to figure out why.

Read more →