destroy method
Destroy this screen 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_Screen_DestroyContext(_context!);
_context = null; // Clear the handle
if (result != bindings.MiniAVResultCode.MINIAV_SUCCESS) {
throw Exception('Failed to destroy screen context: ${result.name}');
}
}
}