Merge from master and fix PR conflicts.
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index 31e82ed..ca8197c 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -26,6 +26,7 @@
to find a cached shader, by only considering resources from the current shader stage.
- Rename `kMVKShaderStageMax` to `kMVKShaderStageCount`.
- Fix crash when requesting `MTLCommandBuffer` logs in runtime debug mode on older OS versions.
+- Protect against crash when retrieving `MTLTexture` when `VkImage` has no `VkDeviceMemory` bound.
- Fix internal reference from `SPIRV_CROSS_NAMESPACE_OVERRIDE` to `SPIRV_CROSS_NAMESPACE`.
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
index 4c2af5c..435d78e 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
@@ -44,6 +44,7 @@
MTLTextureDescriptor* mtlTexDesc = newMTLTextureDescriptor(); // temp retain
MVKImageMemoryBinding* memoryBinding = getMemoryBinding();
+ MVKDeviceMemory* dvcMem = memoryBinding->_deviceMemory;
if (_image->_ioSurface) {
_mtlTexture = [_image->getMTLDevice()
@@ -55,19 +56,19 @@
newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->_mtlTexelBufferOffset + _subresources[0].layout.offset
bytesPerRow: _subresources[0].layout.rowPitch];
- } else if (memoryBinding->_deviceMemory->getMTLHeap() && !_image->getIsDepthStencil()) {
+ } else if (dvcMem && dvcMem->getMTLHeap() && !_image->getIsDepthStencil()) {
// Metal support for depth/stencil from heaps is flaky
- _mtlTexture = [memoryBinding->_deviceMemory->getMTLHeap()
+ _mtlTexture = [dvcMem->getMTLHeap()
newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->getDeviceMemoryOffset() + _subresources[0].layout.offset];
if (_image->_isAliasable) { [_mtlTexture makeAliasable]; }
- } else if (_image->_isAliasable && memoryBinding->_deviceMemory->isDedicatedAllocation() &&
- !contains(memoryBinding->_deviceMemory->_imageMemoryBindings, memoryBinding)) {
+ } else if (_image->_isAliasable && dvcMem && dvcMem->isDedicatedAllocation() &&
+ !contains(dvcMem->_imageMemoryBindings, memoryBinding)) {
// This is a dedicated allocation, but it belongs to another aliasable image.
// In this case, use the MTLTexture from the memory's dedicated image.
// We know the other image must be aliasable, or I couldn't have been bound
// to its memory: the memory object wouldn't allow it.
- _mtlTexture = [memoryBinding->_deviceMemory->_imageMemoryBindings[0]->_image->getMTLTexture(_planeIndex, mtlTexDesc.pixelFormat) retain];
+ _mtlTexture = [dvcMem->_imageMemoryBindings[0]->_image->getMTLTexture(_planeIndex, mtlTexDesc.pixelFormat) retain];
} else {
_mtlTexture = [_image->getMTLDevice() newTextureWithDescriptor: mtlTexDesc];
}