henrybetts / swift-webgpu

Swift bindings for WebGPU
MIT License
89 stars 4 forks source link

Initialize `nextInChain` to `nil` in extensible getters. #8

Closed adamwych closed 6 months ago

adamwych commented 6 months ago

Fixes a crash on macOS when calling (some?) extensible getters (e.g. Adapter.properties). It seems to work fine on Windows without this patch, maybe Swift runtime does something differently on other platforms, not sure.

Extensible getters create the associated C struct (e.g. WGPUAdapterProperties), but it does not reset their nextInChain property to nil, so Dawn crashes thinking that it's pointing to some real thing.

According to Xcode docs, Swift will zero all values after allocating an imported C struct, but apparently it doesn't always do that.

henrybetts commented 6 months ago

That's very strange. Anyway, it's probably better to do it explicitly. Thanks!