Skip to content

Commit a70b833

Browse files
authored
fix: Move DropGuards to the end of their parent structs. (#8353)
1 parent 756dd3c commit a70b833

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ SamplerDescriptor {
9393

9494
- Align copies b/w textures and buffers via a single intermediate buffer per copy when `D3D12_FEATURE_DATA_D3D12_OPTIONS13.UnrestrictedBufferTextureCopyPitchSupported` is `false`. By @ErichDonGubler in [#7721](https://github.com/gfx-rs/wgpu/pull/7721).
9595

96+
#### hal
97+
98+
- `DropCallback`s are now called after dropping all other fields of their parent structs. By @jerzywilczek in [#8353](https://github.com/gfx-rs/wgpu/pull/8353)
99+
96100
## v27.0.2 (2025-10-03)
97101

98102
### Bug Fixes

wgpu-hal/src/gles/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,16 @@ impl TextureInner {
408408
#[derive(Debug)]
409409
pub struct Texture {
410410
pub inner: TextureInner,
411-
pub drop_guard: Option<crate::DropGuard>,
412411
pub mip_level_count: u32,
413412
pub array_layer_count: u32,
414413
pub format: wgt::TextureFormat,
415414
#[allow(unused)]
416415
pub format_desc: TextureFormatDesc,
417416
pub copy_size: CopyExtent,
417+
418+
// The `drop_guard` field must be the last field of this struct so it is dropped last.
419+
// Do not add new fields after it.
420+
pub drop_guard: Option<crate::DropGuard>,
418421
}
419422

420423
impl crate::DynTexture for Texture {}

wgpu-hal/src/vulkan/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub struct DebugUtilsMessengerUserData {
156156
pub struct InstanceShared {
157157
raw: ash::Instance,
158158
extensions: Vec<&'static CStr>,
159-
drop_guard: Option<crate::DropGuard>,
160159
flags: wgt::InstanceFlags,
161160
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
162161
debug_utils: Option<DebugUtils>,
@@ -171,6 +170,10 @@ pub struct InstanceShared {
171170
/// It is associated with a `VkInstance` and its children,
172171
/// except for a `VkPhysicalDevice` and its children.
173172
instance_api_version: u32,
173+
174+
// The `drop_guard` field must be the last field of this struct so it is dropped last.
175+
// Do not add new fields after it.
176+
drop_guard: Option<crate::DropGuard>,
174177
}
175178

176179
pub struct Instance {
@@ -715,7 +718,6 @@ struct DeviceShared {
715718
family_index: u32,
716719
queue_index: u32,
717720
raw_queue: vk::Queue,
718-
drop_guard: Option<crate::DropGuard>,
719721
instance: Arc<InstanceShared>,
720722
physical_device: vk::PhysicalDevice,
721723
enabled_extensions: Vec<&'static CStr>,
@@ -737,6 +739,10 @@ struct DeviceShared {
737739
texture_identity_factory: ResourceIdentityFactory<vk::Image>,
738740
/// As above, for texture views.
739741
texture_view_identity_factory: ResourceIdentityFactory<vk::ImageView>,
742+
743+
// The `drop_guard` field must be the last field of this struct so it is dropped last.
744+
// Do not add new fields after it.
745+
drop_guard: Option<crate::DropGuard>,
740746
}
741747

742748
impl Drop for DeviceShared {
@@ -945,12 +951,15 @@ impl crate::DynAccelerationStructure for AccelerationStructure {}
945951
#[derive(Debug)]
946952
pub struct Texture {
947953
raw: vk::Image,
948-
drop_guard: Option<crate::DropGuard>,
949954
external_memory: Option<vk::DeviceMemory>,
950955
block: Option<gpu_alloc::MemoryBlock<vk::DeviceMemory>>,
951956
format: wgt::TextureFormat,
952957
copy_size: crate::CopyExtent,
953958
identity: ResourceIdentity<vk::Image>,
959+
960+
// The `drop_guard` field must be the last field of this struct so it is dropped last.
961+
// Do not add new fields after it.
962+
drop_guard: Option<crate::DropGuard>,
954963
}
955964

956965
impl crate::DynTexture for Texture {}

0 commit comments

Comments
 (0)