Skip to content

Commit 2d03ef2

Browse files
Merge pull request #356 from P0rc3lain/fix-mip-maps-crashes
Fix crashes that happen during mip map generation
2 parents a685045 + 10d9446 commit 2d03ef2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Engine/Core/Extensions/ModelIO/MDLTexture+Extension.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import ModelIO
77
import simd
88

99
extension MDLTexture {
10+
var canBeMipMapped: Bool {
11+
dimensions.x >= 2 && dimensions.y >= 2
12+
}
1013
static func solid2D(color: simd_float4, name: String) -> MDLTexture {
1114
MDLTexture(data: Data.solid2DTexture(color: color),
1215
topLeftOrigin: true,
@@ -23,7 +26,7 @@ extension MDLTexture {
2326
generateMipMaps: Bool = true) -> MTLTexture? {
2427
let loader = MTKTextureLoader(device: device)
2528
let options: [MTKTextureLoader.Option: Any] = [
26-
.generateMipmaps: true,
29+
.generateMipmaps: canBeMipMapped && generateMipMaps,
2730
.textureUsage: NSNumber(value: usage.rawValue),
2831
.textureStorageMode: NSNumber(value: storageMode.rawValue)
2932
]

0 commit comments

Comments
 (0)