From 853935a5c96062f92c77f61685793b16fe0046e5 Mon Sep 17 00:00:00 2001 From: Per Melin Date: Fri, 1 Mar 2024 13:22:19 +0100 Subject: [PATCH] Fix error in AABB calculation for particles with USERDATA Selecting "Generate AABB" on a 3D particle node in the editor would not work and printed an error about incorrect buffer size if the particle shader used one or more of the USERDATA build-ins. --- drivers/gles3/storage/particles_storage.cpp | 2 +- .../rendering/renderer_rd/storage_rd/particles_storage.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gles3/storage/particles_storage.cpp b/drivers/gles3/storage/particles_storage.cpp index c5a97bdbd51e..4d563ab28b0c 100644 --- a/drivers/gles3/storage/particles_storage.cpp +++ b/drivers/gles3/storage/particles_storage.cpp @@ -395,7 +395,7 @@ AABB ParticlesStorage::particles_get_current_aabb(RID p_particles) { bool first = true; const uint8_t *data_ptr = (const uint8_t *)buffer.ptr(); - uint32_t particle_data_size = sizeof(ParticleInstanceData3D) + sizeof(float) * particles->userdata_count; + uint32_t particle_data_size = sizeof(ParticleInstanceData3D); for (int i = 0; i < total_amount; i++) { const ParticleInstanceData3D &particle_data = *(const ParticleInstanceData3D *)&data_ptr[particle_data_size * i]; diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index a854e78f536f..28b2c9b40c5e 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -620,8 +620,9 @@ AABB ParticlesStorage::particles_get_current_aabb(RID p_particles) { total_amount *= particles->trail_bind_poses.size(); } + uint32_t particle_data_size = sizeof(ParticleData) + sizeof(float) * 4 * particles->userdata_count; Vector buffer = RD::get_singleton()->buffer_get_data(particles->particle_buffer); - ERR_FAIL_COND_V(buffer.size() != (int)(total_amount * sizeof(ParticleData)), AABB()); + ERR_FAIL_COND_V(buffer.size() != (int)(total_amount * particle_data_size), AABB()); Transform3D inv = particles->emission_transform.affine_inverse(); @@ -630,7 +631,6 @@ AABB ParticlesStorage::particles_get_current_aabb(RID p_particles) { bool first = true; const uint8_t *data_ptr = (const uint8_t *)buffer.ptr(); - uint32_t particle_data_size = sizeof(ParticleData) + sizeof(float) * particles->userdata_count; for (int i = 0; i < total_amount; i++) { const ParticleData &particle_data = *(const ParticleData *)&data_ptr[particle_data_size * i];