Skip to content

VTDecompressionSession.DecodeFrame and NewDecompressionCallback #17394

Closed

Description

@BlackTr

When calling a VTDecompressionSession.DecodeFrame in Visual Studio for Mac 17.4.3 with wrong buffer data for decoder, the Callback not called and application crashed.

Steps to Reproduce

// callback
private void OutputCallback(IntPtr sourceFrame,
    VTStatus status,
    VTDecodeInfoFlags vtDecodeInfoFlags,
    CVImageBuffer buffer,
    CMTime presentationTimestamp,
    CMTime presentationDuration)
{
}

// create session
_decSession = VTDecompressionSession.Create(OutputCallback,
            _formatDescription,
            videoDecoderSpecification,
            destinationImageBufferAttributes);

// decode frame
var decodeStatus = _decSession.DecodeFrame(sampleBuffer, VTDecodeFrameFlags.EnableAsynchronousDecompression, IntPtr.Zero, out VTDecodeInfoFlags infoFlags);

Expected Behavior

The Callback is called and provide null in CVImageBuffer buffer and provide error in VTStatus status if possible

Actual Behavior

The Callback not called and application crashed with exception:

Maui[20537:2930599] *** Terminating app due to uncaught exception 'System.Exception', reason: 'Could not initialize an instance of the type 'CoreVideo.CVPixelBuffer': handle is null.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false. (System.Exception)
   at ObjCRuntime.DisposableObject.InitializeHandle(NativeHandle handle, Boolean verify)
   at ObjCRuntime.DisposableObject..ctor(NativeHandle handle, Boolean owns, Boolean verify)
   at CoreFoundation.NativeObject..ctor(NativeHandle handle, Boolean owns, Boolean verify)
   at CoreVideo.CVBuffer..ctor(NativeHandle handle, Boolean owns)
   at CoreVideo.CVImageBuffer..ctor(NativeHandle handle, Boolean owns)
   at CoreVideo.CVPixelBuffer..ctor(NativeHandle handle, Boolean owns)
   at VideoToolbox.VTDecompressionSession.NewDecompressionCallback(IntPtr outputCallbackClosure, IntPtr sourceFrame, VTStatus status, VTDecodeInfoFlags infoFlags, IntPtr imageBufferPtr, CMTime presentationTimeStamp, CMTime presentationDuration)
'

Environment

Version information
Visual Studio Enterprise 2022 for Mac
Version 17.4.3 (build 21)
Installation UUID: 5c1fe431-71a3-473a-9c74-2dc970827e97

Runtime
.NET 6.0.12 (64-bit)
Architecture: X64

Roslyn (Language Service)
4.4.0-6.22578.12+3c6ab8e1715e5b080fb7bb77070810ab71e09387

NuGet
Version: 6.3.1.1

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/7.0.102/Sdks
SDK Versions:
	7.0.102
	7.0.101
	7.0.100
	6.0.405
	6.0.404
	6.0.403
	6.0.402
	6.0.401
	6.0.201
	6.0.100
	3.1.426
	3.1.425
	3.1.424
	3.1.423
	3.1.417
	3.1.401
	2.2.103
	2.1.302
	2.1.4
	2.0.0
	2.0.0-preview2-006127
	1.0.4
	1.0.1
	1.0.0-preview2-003131
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.2
	7.0.1
	7.0.0
	6.0.13
	6.0.12
	6.0.11
	6.0.10
	6.0.9
	6.0.3
	6.0.0
	3.1.32
	3.1.31
	3.1.30
	3.1.29
	3.1.23
	3.1.7
	2.2.1
	2.1.2
	2.1.0
	2.0.5
	2.0.0
	2.0.0-preview2-25319-02
	1.1.2
	1.1.1
	1.0.5
	1.0.4
	1.0.1

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Version: 13.1.0.1 (Visual Studio Enterprise)
Commit: xamarin-android/d17-4/13ba222
Android SDK: /Users/Aleksey/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0  (API level 23)
		12.0 (API level 31)
		13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 32.0.0

Build Information: 
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
SQLite: xamarin/sqlite/3.39.3@23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.4.0.54
Hash: 6eabb9e
Branch: remotes/origin/d17-4
Build date: 2023-01-12 19:21:16 UTC

Android Device Manager
Version: 0.0.0.1206
Hash: 886af39
Branch: 886af39
Build date: 2023-01-12 19:21:16 UTC

Apple Developer Tools
Xcode 14.2 (21534)
Build 14C18

Xamarin.Mac
Version: 9.0.0.27 (Visual Studio Enterprise)
Hash: 933c6c2c9
Branch: xcode14.1
Build date: 2022-11-22 02:00:36-0500

Xamarin.iOS
Version: 16.1.1.27 (Visual Studio Enterprise)
Hash: 933c6c2c9
Branch: xcode14.1
Build date: 2022-11-22 02:00:37-0500

Xamarin Designer
Version: 17.4.0.136
Hash: d49c9ff6d3
Branch: remotes/origin/d17-4
Build date: 2023-01-12 19:21:10 UTC

Build Information
Release ID: 1704030021
Git revision: 26eac6764d85f12fe50ee0d45a7cd0b266be7b23
Build date: 2023-01-12 19:19:02+00
Build branch: release-17.4
Build lane: release-17.4

Operating System
Mac OS X 12.6.2
Darwin 21.6.0 Darwin Kernel Version 21.6.0
    Sun Nov  6 23:31:16 PST 2022
    root:xnu-8020.240.14~1/RELEASE_X86_64 x86_64

Activity

  1. added
    good first issue
    on Jan 30, 2023
  2. added this to the Future milestone on Jan 30, 2023
  3. rolfbjarne commented on Jan 30, 2023

    @rolfbjarne
    Member

    Thanks for reporting this issue!

  4. added
    enhancement
    on Jan 30, 2023
  5. robopp55 commented on Jan 28, 2024

    @robopp55

    I'm running into this bug right now feeding VTDecompressionSesssion.DecodeFrame with valid H265 data. The encoded data is valid and the decoding works on Android, but I'm getting a cryptic error with nothing else to go on on iOS:

    08:30:25:767 **ObjCRuntime.ObjCException:** 'Objective-C exception thrown. Name: System.Exception Reason: Could not initialize an instance of the type 'CoreVideo.CVPixelBuffer': handle is null. 08:30:25:767 It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false. (System.Exception) 08:30:25:767 at ObjCRuntime.DisposableObject.InitializeHandle(NativeHandle handle, Boolean verify) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/DisposableObject.cs:line 81 08:30:25:767 at ObjCRuntime.DisposableObject..ctor(NativeHandle handle, Boolean owns, Boolean verify) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/DisposableObject.cs:line 51 08:30:25:767 at CoreFoundation.NativeObject..ctor(NativeHandle handle, Boolean owns, Boolean verify) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreFoundation/NativeObject.cs:line 53 08:30:25:767 at CoreVideo.CVBuffer..ctor(NativeHandle handle, Boolean owns) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreVideo/CVBuffer.cs:line 56 08:30:25:767 at CoreVideo.CVImageBuffer..ctor(NativeHandle handle, Boolean owns) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreVideo/CVImageBuffer.cs:line 54 08:30:25:767 at CoreVideo.CVPixelBuffer..ctor(NativeHandle handle, Boolean owns) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreVideo/CVPixelBuffer.cs:line 38 08:30:25:767 at VideoToolbox.VTDecompressionSession.NewDecompressionCallback(IntPtr outputCallbackClosure, IntPtr sourceFrame, VTStatus status, VTDecodeInfoFlags infoFlags, IntPtr imageBufferPtr, CMTime presentationTimeStamp, CMTime presentationDuration) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/VideoToolbox/VTDecompressionSession.cs:line 148 08:30:25:767 08:30:25:767 Native stack trace: 08:30:25:767 0 CoreFoundation 0x00000001a1fa1e54 725E49F4-653B-39BF-9A7A-8A3250911ECB + 40532 08:30:25:767 1 libobjc.A.dylib 0x000000019b2eb8d8 objc_exception_throw + 60 08:30:25:767 2 Xamarin.PreBuilt.iOS 0x00000001003e9850 xamarin_locate_assembly_resource + 2748 08:30:25:767 3 Xamarin.PreBuilt.iOS 0x00000001003e9370 xamarin_locate_assembly_resource + 1500 08:30:25:767 4 Xamarin.PreBuilt.iOS 0x00000001003e9320 xamarin_locate_assembly_resource + 1420 08:30:25:767 5 Xamarin.PreBuilt.iOS 0x00000001006fbdec AppleCryptoNative_X509ImportCollection + 2698900 08:30:25:767 6 Xamarin.PreBuilt.iOS 0x00000001006fa964 AppleCryptoNative_X509ImportCollection + 2693644 08:30:25:767 7 Xamarin.PreBuilt.iOS 0x0000000100721778 AppleCryptoNative_X509ImportCollection + 2852896 08:30:25:767 8 Xamarin.PreBuilt.iOS 0x000000010071fa3c AppleCryptoNative_X509ImportCollection + 2845412 08:30:25:767 9 Xamarin.PreBuilt.iOS 0x000000010071a9f0 AppleCryptoNative_X509ImportCollection + 2824856 08:30:25:767 10 Xamarin.PreBuilt.iOS 0x0000000100712510 AppleCryptoNative_X509ImportCollection + 2790840 08:30:25:767 11 Xamarin.PreBuilt.iOS 0x00000001003b9a18 Xamarin.PreBuilt.iOS + 88600 08:30:25:767 12 VideoToolbox 0x00000001b0e19540 29B708EC-A63D-393F-856F-2F8C8D1782FD + 3003712 08:30:25:767 13 libdispatch.dylib 0x00000001a95af4b4 24DB930D-870B-31CE-AC69-534D7896B4A8 + 9396 08:30:25:767 14 libdispatch.dylib 0x00000001a95b0fdc 24DB930D-870B-31CE-AC69-534D7896B4A8 + 16348 08:30:25:767 15 libdispatch.dylib 0x00000001a95b8774 24DB930D-870B-31CE-AC69-534D7896B4A8 + 46964 08:30:25:767 16 libdispatch.dylib 0x00000001a95b91e0 24DB930D-870B-31CE-AC69-534D7896B4A8 + 49632 08:30:25:767 17 libdispatch.dylib 0x00000001a95c3e10 24DB930D-870B-31CE-AC69-534D7896B4A8 + 93712 08:30:25:767 18 libsystem_pthread.dylib 0x00000001ef6b5df8 _pthread_wqthread + 288 08:30:25:767 19 libsystem_pthread.dylib 0x00000001ef6b5b98 start_wqthread + 8

    Is there a way to get more error info like callback VTStatus as mentioned by the OP, or at least something to go on?

  6. robopp55 commented on Jan 28, 2024

    @robopp55

    Setting ObjCRuntime.Class.ThrowOnInitFailure = false; allows the error to propagate through to the VTDecompressionOutputCallback handler with the error. In my case it's throwing a VideoDecoderBadData, which is odd.

  7. self-assigned this
    on Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-bindingsenhancementgood first issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions