destroy method

  1. @override
Future<void> destroy()
override

Destroy this camera context and release resources.

Implementation

@override
Future<void> destroy() async {
  // Idempotent - can be called multiple times safely
  if (_isDestroyed) {
    return; // Already destroyed
  }

  _isDestroyed = true; // Mark as destroyed first to prevent new operations

  await stopCapture(); // Stop capture if running

  if (_context != null) {
    _finalizer.detach(this); // Prevent finalizer from running
    final result = bindings.MiniAV_Camera_DestroyContext(_context!);
    _context = null; // Clear the handle

    if (result != bindings.MiniAVResultCode.MINIAV_SUCCESS) {
      throw Exception('Failed to destroy camera context: ${result.name}');
    }
  }
}