C
C#7mo ago
A

Unknown Access Violation Error

Hi, I am getting the error in the picture below, but I am not doing anything that would cause the error to happen. This is the "NativeNewContext" function
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();
And this is the function in c++
struct GlyphContext
{
msdfgen::Point2 position{};
msdfgen::Shape * shape;
msdfgen::Contour * contour;
GlyphContext();
~GlyphContext();
};


EXPORT GlyphContext * msdfNewContext();

GlyphContext * msdfNewContext()
{
return new GlyphContext();
}
struct GlyphContext
{
msdfgen::Point2 position{};
msdfgen::Shape * shape;
msdfgen::Contour * contour;
GlyphContext();
~GlyphContext();
};


EXPORT GlyphContext * msdfNewContext();

GlyphContext * msdfNewContext()
{
return new GlyphContext();
}
No description
9 Replies
Omnissiah
Omnissiah7mo ago
do you have other calls like that? error could be caused before of that point (does crash occour if that method is not called?) would you mind trying stdcall instead of cdecl?
A
AOP7mo ago
I have other pinvokes but they are for other dlls all the ones for this specific dll is in this file
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeFreeContext(IntPtr context);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextMoveTo", CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeMoveTo(IntPtr context, ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextQuadraticBezierTo",
CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeQuadraticBezierTo(IntPtr context, ref Vector2<float> control,
ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextCubicBezierTo",
CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeCubicBezierTo(IntPtr context, ref Vector2<float> control1,
ref Vector2<float> control2,
ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextLineTo", CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeLineTo(IntPtr context, ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeEnd(IntPtr context);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeRender(IntPtr context,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeGenerateDelegate onRendered);
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeFreeContext(IntPtr context);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextMoveTo", CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeMoveTo(IntPtr context, ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextQuadraticBezierTo",
CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeQuadraticBezierTo(IntPtr context, ref Vector2<float> control,
ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextCubicBezierTo",
CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeCubicBezierTo(IntPtr context, ref Vector2<float> control1,
ref Vector2<float> control2,
ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfGlyphContextLineTo", CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeLineTo(IntPtr context, ref Vector2<float> to);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeEnd(IntPtr context);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeRender(IntPtr context,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeGenerateDelegate onRendered);
and the program runs if I dont call any of these i.e. no other errors no dice with stdcall same error at the same place
Omnissiah
Omnissiah7mo ago
ok then so does just calling NativeNewContext cause a crash? because if it is then since it's so short it could be worth looking at disassembly ALSO i would like to point out that the import
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();
[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr NativeNewContext();
is pointing to msdfRenderContext and not msdfNewContext
A
AOP7mo ago
Omg Omfg How did I not notice the name
A
AOP7mo ago
now one of the dll functions are not being exported it's like I am being punished
Omnissiah
Omnissiah7mo ago
sadly programming can be like that
A
AOP7mo ago
I fixed the above but now I get the acces violation here
No description
A
AOP7mo ago
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void NativeGenerateDelegate(IntPtr data, uint width, uint height, uint byteSize);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeRender(IntPtr context,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeGenerateDelegate onRendered);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void NativeGenerateDelegate(IntPtr data, uint width, uint height, uint byteSize);

[DllImport(Dlls.AeroxWidgetsNative, EntryPoint = "msdfRenderContext",CallingConvention = CallingConvention.Cdecl)]
private static extern void NativeRender(IntPtr context,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeGenerateDelegate onRendered);
using RenderMsdfCallback = void(__stdcall *)(void * data,uint32_t width,uint32_t height,uint32_t size);
EXPORT void msdfRenderContext(GlyphContext * context,RenderMsdfCallback callback);
using RenderMsdfCallback = void(__stdcall *)(void * data,uint32_t width,uint32_t height,uint32_t size);
EXPORT void msdfRenderContext(GlyphContext * context,RenderMsdfCallback callback);
Want results from more Discord servers?
Add your server