Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emission_shape_changed signal error when using ShaderMaterial with GPUParticles3D #101617

Merged

Conversation

paddy-exe
Copy link
Contributor

@paddy-exe paddy-exe commented Jan 16, 2025

Comment on lines 150 to 165
if (process_material.is_valid()) {
material_rid = process_material->get_rid();
} else if (cast_to<ParticleProcessMaterial>(*process_material)) {
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, since the process_material.is_valid() condition is true, so it will never evaluate the else if.
It should be:

Suggested change
if (process_material.is_valid()) {
material_rid = process_material->get_rid();
} else if (cast_to<ParticleProcessMaterial>(*process_material)) {
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
}
if (process_material.is_valid()) {
material_rid = process_material->get_rid();
if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
}
}

@akien-mga akien-mga changed the title Fix emission_shape_changed signal error when using ShaderMaterial with 3DGPUParticlesNode Fix emission_shape_changed signal error when using ShaderMaterial with 3DGPUParticlesNode Jan 16, 2025
@akien-mga akien-mga changed the title Fix emission_shape_changed signal error when using ShaderMaterial with 3DGPUParticlesNode Fix emission_shape_changed signal error when using ShaderMaterial with GPUParticles3D Jan 16, 2025
@akien-mga
Copy link
Member

There are some more issues with #100113 and its follow-up #101537:

  • Fix regression from already disconnected emission shape changed signal #101537 removed the signal disconnect, but not the previous two lines which you just added to be able to disconnect the signal. These should be removed too. But I wonder: when is the signal disconnected now? What happens if you set the same ParticleProcessMaterial twice in a GPUParticles3D? Won't it error that the signal is already connected? The way we handle this usually is that the set_process_material setter should first check if the current material needs the signal disconnected, before assigning the new material and connecting the signal.
  • The signal is emitted only in TOOLS_ENABLED, but this isn't documented, and there's still code like here that connects it in non-TOOLS_ENABLED builds.
  • Finally there's [4.4-beta1] Loading compute shader on Linux crashes the editor #101611 which is why I started looking into Add visualization of 3D particle emission shapes #100113, but the above nitpicks don't seem to be what's causing the crash. I haven't had time to investigate further yet.

@paddy-exe paddy-exe force-pushed the processmaterial-vs-shadermaterial branch from 3bc5c7c to 1d83a95 Compare January 16, 2025 20:16
@paddy-exe paddy-exe requested a review from a team as a code owner January 16, 2025 20:16
@paddy-exe
Copy link
Contributor Author

paddy-exe commented Jan 16, 2025

Alright, I think I have solved the problem with ShaderMaterial and the signal connect and disconnect. Also added a documentation note in the class reference. In the CurveEdit class at least when setting a new curve you disconnect the signals and then re-add them to the new assigned one (see here) so I took inspiration from that.

I tested the various problem cases removing and re-adding the same material, adding a ShaderMaterial instead, using the same material on several GPUParticles3D Nodes and haven't encountered any errors or crashes (together with #101636 that is).

scene/3d/gpu_particles_3d.cpp Outdated Show resolved Hide resolved
scene/3d/gpu_particles_3d.cpp Outdated Show resolved Hide resolved
@paddy-exe paddy-exe force-pushed the processmaterial-vs-shadermaterial branch from 1d83a95 to 484d6d4 Compare January 17, 2025 14:07
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be good to get this field-tested early

@Repiteo Repiteo merged commit 923eb44 into godotengine:master Jan 17, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 17, 2025

Thanks!

@paddy-exe paddy-exe deleted the processmaterial-vs-shadermaterial branch January 17, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GPUParticles3D cannot set ShaderMaterial in process_material
5 participants