浏览代码

vulkan: gracefully handle inability to create device

rdb 7 年之前
父节点
当前提交
b7865a3716

+ 5 - 0
panda/src/vulkandisplay/vulkanGraphicsStateGuardian.cxx

@@ -309,6 +309,11 @@ VulkanGraphicsStateGuardian(GraphicsEngine *engine, VulkanGraphicsPipe *pipe,
  */
  */
 VulkanGraphicsStateGuardian::
 VulkanGraphicsStateGuardian::
 ~VulkanGraphicsStateGuardian() {
 ~VulkanGraphicsStateGuardian() {
+  if (_device == VK_NULL_HANDLE) {
+    nassertv(_memory_pages.empty());
+    return;
+  }
+
   // And all the semaphores that were generated on this device.
   // And all the semaphores that were generated on this device.
   for (VkSemaphore semaphore : _semaphores) {
   for (VkSemaphore semaphore : _semaphores) {
     vkDestroySemaphore(_device, semaphore, nullptr);
     vkDestroySemaphore(_device, semaphore, nullptr);

+ 7 - 0
panda/src/vulkandisplay/vulkanGraphicsWindow.cxx

@@ -447,6 +447,13 @@ open_window() {
     DCAST_INTO_R(vkgsg, _gsg.p(), false);
     DCAST_INTO_R(vkgsg, _gsg.p(), false);
   }
   }
 
 
+  if (!vkgsg->is_valid()) {
+    _gsg.clear();
+    vulkandisplay_cat.error()
+      << "VulkanGraphicsStateGuardian is not valid.\n";
+    return false;
+  }
+
   _fb_properties.set_force_hardware(vkgsg->is_hardware());
   _fb_properties.set_force_hardware(vkgsg->is_hardware());
   _fb_properties.set_force_software(!vkgsg->is_hardware());
   _fb_properties.set_force_software(!vkgsg->is_hardware());