Files
faceclaw/app/native/kotlin-protocol-smoke.ts
T
James BabcockandClaude Opus 5.5 1812818ae2 Stop leaking the remaining JS ArrayBuffers passed to Java
The same NativeScript conversion leak as the frame path (see
java-direct-buffer.ts) applied to every other ArrayBuffer handed to a
Java ByteBuffer parameter:

- Shell scenes (submitShellScene on the bridge and the preview display),
  submitted on every shell render, which the frame-path fix predates.
  These now go through a reused JavaDirectBuffer like frames do.
- Glyph, firmware-glyph and image atlas registration, Mapbox image
  decode, the preview placeholder bitmap, firmware hash/write, binary
  file writes and the EvenHub privacy-policy download, plus the Kotlin
  protocol smoke test. These are rare or large, so they cross through a
  new copyToJavaByteBuffer: a fresh Java direct buffer per call that is
  freed normally, rather than one pinned for the life of the isolate.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 22:28:45 -07:00

23 lines
1.4 KiB
TypeScript

import { copyToJavaByteBuffer } from './java-direct-buffer'
declare const com: any
/** Development-only checks of NativeScript metadata and bulk ByteBuffer crossings. */
export function runKotlinProtocolSmokeTest(): void {
const native = com.faceclaw.app
const hex = (data: any) => Array.from({ length: data.length }, (_, i) => (data[i] & 255).toString(16).padStart(2, '0')).join('')
const assert = (condition: boolean, what: string) => { if (!condition) throw new Error(`Kotlin protocol bridge: ${what}`) }
const auth = native.BleProtocol.buildAuthenticationRequest(101)
assert(hex(auth) === '080410651a0408011004', 'authentication')
const compositor = new native.SurfaceCompositor()
compositor.configureScreen(3, 2)
compositor.configureSurface('test', 0, 0, 3, 2, 0, 0)
const pixels = copyToJavaByteBuffer(new Uint8Array([0, 16, 255, 32, 48, 64]))
compositor.submitSurface('test', new native.AndroidByteReader(pixels), 0, 0, 3, 2, '1')
assert(hex(compositor.composite().gray) === '0010ff203040', 'composition/ByteBuffer')
assert(hex(native.BmpUtil.pack4bppFromGray8(compositor.composite().gray, 3, 2)) === '01f02340', 'packing')
const id = native.ImageAtlas.ensure('kotlin-smoke', 3, 2, new native.AndroidByteReader(pixels))
assert(id > 0 && native.ImageAtlas.get(id).width === 3, 'image atlas/reused buffer')
console.log('FACECLAW_KOTLIN_PROTOCOL_PASS Android')
}