Bildressource in imageDataFromFile mit try/finally freigeben

Stelle sicher, dass bitmap.close() auch bei Fehler aufgerufen wird.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
vchuser
2026-07-28 16:28:18 +02:00
co-authored by Claude Opus 5
parent 91ac8b9db6
commit 1192a898c4
+4 -1
View File
@@ -67,8 +67,11 @@ export function grabFrame(videoElement, maxEdge = 1280) {
/** Ersatzweg ohne Kamera: Bilddatei auswaehlen (z. B. am Rechner). */ /** Ersatzweg ohne Kamera: Bilddatei auswaehlen (z. B. am Rechner). */
export async function imageDataFromFile(file, maxEdge = 1280) { export async function imageDataFromFile(file, maxEdge = 1280) {
const bitmap = await createImageBitmap(file); const bitmap = await createImageBitmap(file);
try {
assertHasSize(bitmap.width, bitmap.height); assertHasSize(bitmap.width, bitmap.height);
const data = drawScaled(bitmap, bitmap.width, bitmap.height, maxEdge); const data = drawScaled(bitmap, bitmap.width, bitmap.height, maxEdge);
bitmap.close();
return data; return data;
} finally {
bitmap.close();
}
} }