Absturz mit EXC_BAD_ACCESS (SIGSEGV) in .NET 8 und Silk.NET VulkanC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Absturz mit EXC_BAD_ACCESS (SIGSEGV) in .NET 8 und Silk.NET Vulkan

Post by Anonymous »

Bitte helfen Sie! Ich programmiere mit .NET 8 auf macOS und Silk.NET Vulkan-Bibliotheken.
Ich habe die MoltenVK-Bibliotheken zum Ausgabeordner hinzugefügt, aber nachdem ich etwas Vulkan-Code hinzugefügt hatte, stürzte es ab.
Ich habe mir ein YouTube-Tutorial angesehen, um die Grundlagen von Vulkan und seine Verwendung zu lernen. Ich habe den Code debuggt und er ist abgestürzt. Nachdem ich den Bericht gelesen hatte, dachte ich, dass es daran lag, dass ich die kompilierte Binärbibliothek von MoltenVK verwendet hatte und nicht die „originalen“ von Nvidia oder AMD für Linux/Windows.
Könnte mir bitte jemand erklären, ob ich Recht habe und wenn ja, warum?
Hier ist der Bericht vom Absturz: (Der Code folgt danach.)

Code: Select all

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000b10
Exception Codes:       0x0000000000000001, 0x0000000000000b10

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler \[1597\]

VM Region Info: 0xb10 is not in any region.   Bytes before following region: 4389373168
REGION TYPE                    START - END         \[ VSIZE\] PRT/MAX SHRMOD  REGION DETAIL
UNUSED SPACE AT START
\---\>
\__TEXT                      105a09000-105a15000    \[   48K\] r-x/r-x SM=COW  /usr/local/share/dotnet/dotnet

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libvulkan.1.dylib                      0x37b481b31 MVKInstance::getPhysicalDevices(unsigned int\*, VkPhysicalDevice_T\*\*) + 17
1   libvulkan.1.dylib                      0x37b4684fc vkEnumeratePhysicalDevices + 60
2   ???                                    0x2cd97916a ???
3   ???                                    0x2cd97900a ???
4   ???                                    0x2cd978d9d ???
5   ???                                    0x2cd975d06 ???
6   ???                                    0x2cd951b38 ???
7   ???                                    0x2cd951993 ???
8   libcoreclr.dylib                       0x2cc76ce01 CallDescrWorkerInternal + 124
9   libcoreclr.dylib                       0x2cc5cce23 MethodDescCallSite::CallTargetWorker(unsigned long long const\*, unsigned long long\*, int) + 1587
10  libcoreclr.dylib                       0x2cc4c65a8 RunMain(MethodDesc\*, short, int\*, PtrArray\*\*) + 712
11  libcoreclr.dylib                       0x2cc4c69b2 Assembly::ExecuteMainMethod(PtrArray\*\*, int) + 450
12  libcoreclr.dylib                       0x2cc4f0da1 CorHost2::ExecuteAssembly(unsigned int, char16_t const\*, int, char16_t const\*\*, unsigned int\*) + 689
13  libcoreclr.dylib                       0x2cc4b3b92 coreclr_execute_assembly + 226
14  libhostpolicy.dylib                    0x1dec3956d run_app_for_context(hostpolicy_context_t const&, int, char const\*\*) + 2013
15  libhostpolicy.dylib                    0x1dec3a4e4 corehost_main + 276
16  libhostfxr.dylib                       0x105babe35 fx_muxer_t::handle_exec_host_command(std::\__1::basic_string\ const&, host_startup_info_t const&, std::\__1::basic_string\ const&, std::\__1::unordered_map\  const&, int, char const\*\*, int, host_mode_t, bool, char\*, int, int\*) + 1365
17  libhostfxr.dylib                       0x105baaf41 fx_muxer_t::execute(std::\__1::basic_string\, int, char const\*\*, host_startup_info_t const&, char\*, int, int\*) + 977
18  libhostfxr.dylib                       0x105ba7c63 hostfxr_main_startupinfo + 131
19  dotnet                                 0x105a12e4d exe_start(int, char const\*\*) + 1261
20  dotnet                                 0x105a1306f main + 175
21  dyld                                0x7ff805282530 start + 3056
Der Code, in dem es passiert, ist hier:

Code: Select all

public unsafe class VulkanContext
{
public Vk nativeContext = null!;
public Instance intance;
public PhysicalDevice device;
public PhysicalDeviceProperties deviceProperties;
public Device deviceObject;
public VulkanQueue graphicsQueue;
public string error = "";
public static VulkanContext InitVulkan()
{
VulkanContext ctx = null;
ctx = InitVulkanInstance();
if (ctx == null)
{
throw new Exception("can't create vulkan instance!");
}
ctx = selectDevice(ctx);
if (ctx == null)
{
throw new Exception("can't find any gpu that supports vulkan!");
}
//ctx = createLogicalDevice(ctx, 0, null);
if (ctx == null)
{
throw new Exception("can't select any gpu!");
}
return ctx;
}
private static VulkanContext createLogicalDevice(VulkanContext ctx, in uint extcount, byte** extnames)
{
VulkanContext context= ctx;
uint qeuescount = 0;
ctx.nativeContext.GetPhysicalDeviceQueueFamilyProperties(ctx.device, &qeuescount);
QueueFamilyProperties[] props = new QueueFamilyProperties[qeuescount];
ctx.nativeContext.GetPhysicalDeviceQueueFamilyProperties(ctx.device, &qeuescount, props);
uint queuegraphicsindex = 0;
for (uint i = 0; i< qeuescount; i++){
QueueFamilyProperties propsx = props[i];
if(propsx.QueueCount > 0)
{
if(propsx.QueueFlags == QueueFlags.GraphicsBit)
{
queuegraphicsindex = i;
break;
}
}
}
float prio = 1.0f;
DeviceQueueCreateInfo qcreateinfo = new DeviceQueueCreateInfo
{
SType = StructureType.DeviceQueueCreateInfo,
QueueFamilyIndex = queuegraphicsindex,
QueueCount = 1,
PQueuePriorities = &prio
};
PhysicalDeviceFeatures feat = new PhysicalDeviceFeatures { };
DeviceCreateInfo dcreateInfo = new DeviceCreateInfo
{
QueueCreateInfoCount = 1,
PQueueCreateInfos = &qcreateinfo,
EnabledExtensionCount = extcount,
PpEnabledExtensionNames = extnames,
PEnabledFeatures = &feat,
};
if(ctx.nativeContext.CreateDevice(ctx.device, in dcreateInfo, null, out ctx.deviceObject) != Result.Success)
{
return null;
}
ctx.graphicsQueue.familiyIndex = queuegraphicsindex;
ctx.nativeContext.GetDeviceQueue(ctx.deviceObject, queuegraphicsindex,  0, out ctx.graphicsQueue.queue);
return context;
}

private static VulkanContext selectDevice(VulkanContext ctx)
{
VulkanContext context = ctx;
uint devicecount = 1;
//ctx.nativeContext.EnumeratePhysicalDevices(ctx.intance, &devicecount, null);
//if(devicecount == 0)
//{
//  throw new Exception("Can't load Vulkan Device.");
//}
PhysicalDevice[] devices = new PhysicalDevice[1];
ctx.nativeContext.EnumeratePhysicalDevices(ctx.intance, &devicecount, devices);
for (uint i = 0; i < devicecount;  i++)
{
PhysicalDeviceProperties props = new PhysicalDeviceProperties { };
ctx.nativeContext.GetPhysicalDeviceProperties(devices[i], &props);
}
ctx.device = devices[0];
ctx.nativeContext.GetPhysicalDeviceProperties(ctx.device, out ctx.deviceProperties);
return context;
}

private static VulkanContext InitVulkanInstance()
{
ApplicationInfo appinfo = new ApplicationInfo
{
SType = StructureType.ApplicationInfo,
ApiVersion = Vk.MakeVersion(1,2),
};
string[] etxs = new string[2];
etxs[0] = "VK_KHR_surface";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
etxs[1] = "VK_MVK_macos_surface";
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if(System.Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "wayland")
etxs[1] = "VK_KHR_wayland_surface";
else if (System.Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "x11")
etxs[1] = "VK_KHR_xlib_surface";
else if (System.Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "xcb")
etxs[1] = "VK_KHR_xcb_surface";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
etxs[1] = "VK_KHR_win32_surface";
}
InstanceCreateInfo createInfo = new InstanceCreateInfo
{
PApplicationInfo = &appinfo,
EnabledExtensionCount = 2,
PpEnabledExtensionNames = (byte**)SilkMarshal.StringArrayToPtr(etxs),
EnabledLayerCount = 1,
PpEnabledLayerNames = (byte**)SilkMarshal.StringArrayToPtr(new String[] { "VK_LAYER_KHRONOS_validation" }),
SType = StructureType.InstanceCreateInfo,
};
Instance inst;
Vk.GetApi(ref createInfo, out inst);
VulkanContext ctx = new VulkanContext
{
nativeContext = Vk.GetApi(),
intance = inst,
};
return ctx;
}
}
Vielen Dank im Voraus für Ihre Hilfe.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post