FFmpeg.AutoGen icon indicating copy to clipboard operation
FFmpeg.AutoGen copied to clipboard

Invalid generated delegate AVClass_item_name (returns string instead of byte*)

Open SuRGeoNix opened this issue 1 year ago • 3 comments

Hi @Ruslan-B,

Got an access violation with this delegate and fixed it by returning byte*. Eg:-

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate byte* AVClass_item_nameX (void* @ctx); // FFmpeg.Autogen bug

public static string? GetProtocolName(AVIOContext* pb)
{
	if (pb == null || pb->av_class == null || pb->av_class->child_next.Pointer == nint.Zero)
		return null;

	var ChildNext = (AVClass_child_next) Marshal.GetDelegateForFunctionPointer(pb->av_class->child_next.Pointer, typeof(AVClass_child_next));
	var child = ChildNext(pb, null);
	var cl = *(AVClass **)child;

	if (cl == null || cl->item_name.Pointer == nint.Zero)
		return null;

	var ItemName = (AVClass_item_nameX) Marshal.GetDelegateForFunctionPointer(cl->item_name.Pointer, typeof(AVClass_item_nameX));

	return Marshal.PtrToStringUTF8((nint)ItemName(child));
}

Might also worth implicit cast from all _func to delegates?

SuRGeoNix avatar May 13 '23 16:05 SuRGeoNix