Skip to content

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

@SuRGeoNix

Description

@SuRGeoNix

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions