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

Editor crash when Particles Shape is setting to Points and Emission Source is setting to Surface Points+Normal(Directed) #51424

Closed
snougo opened this issue Aug 9, 2021 · 3 comments

Comments

@snougo
Copy link

snougo commented Aug 9, 2021

Godot version

3.4 beta2, 3.4 beta3

System information

MacOS 10.14.6 intel GPU GLES3

Issue description

When Particles's Emission Shape is setting to Points, and using Toolbar's Particles Button to create Emission Source > Surface Points+Normal(Directed), Editor will crash, but if Emission Shape is setting to like Point or Box or other shape, crash won't happen.

Steps to reproduce

create a Particles Node
create a Meshinstance Node and give mesh property a mesh resource
set Emission Shape to Points
click Toolbar's Particles Button
chose Create Emission Points from Node
select the meshinstance node
set Emission Source to Surface Points+Normal(Directed)
click the create button

Minimal reproduction project

particles.zip

@akien-mga
Copy link
Member

akien-mga commented Aug 9, 2021

I can reproduce the crash in 8db0bd4.

$ godot-3.x -e
Godot Engine v3.4.beta.custom_build.8db0bd442 - https://godotengine.org
Found discrete GPU, setting DRI_PRIME=1 to use it.
Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.
OpenGL ES 3.0 Renderer: AMD VEGAM (DRM 3.41.0, 5.13.9-desktop-1.mga9, LLVM 12.0.1)
OpenGL ES Batching: ON
 
    1 | shader_type particles;
    2 | uniform vec3 direction;
    3 | uniform float spread;
    4 | uniform float flatness;
    5 | uniform float initial_linear_velocity;
    6 | uniform float initial_angle;
    7 | uniform float angular_velocity;
    8 | uniform float orbit_velocity;
    9 | uniform float linear_accel;
   10 | uniform float radial_accel;
   11 | uniform float tangent_accel;
   12 | uniform float damping;
   13 | uniform float scale;
   14 | uniform float hue_variation;
   15 | uniform float anim_speed;
   16 | uniform float anim_offset;
   17 | uniform float initial_linear_velocity_random;
   18 | uniform float initial_angle_random;
   19 | uniform float angular_velocity_random;
   20 | uniform float orbit_velocity_random;
   21 | uniform float linear_accel_random;
   22 | uniform float radial_accel_random;
   23 | uniform float tangent_accel_random;
   24 | uniform float damping_random;
   25 | uniform float scale_random;
   26 | uniform float hue_variation_random;
   27 | uniform float anim_speed_random;
   28 | uniform float anim_offset_random;
   29 | uniform float lifetime_randomness;
   30 | uniform sampler2D emission_texture_normal : hint_black;
   31 | uniform sampler2D emission_texture_points : hint_black;
   32 | uniform int emission_texture_point_count;
   33 | uniform vec4 color_value : hint_color;
   34 | uniform int trail_divisor;
   35 | uniform vec3 gravity;
   36 | uniform sampler2D color_ramp;
   37 | uniform sampler2D linear_accel_texture;
   38 | uniform sampler2D scale_texture;
   39 | uniform sampler2D trail_color_modifier;
   40 | 
   41 | 
   42 | float rand_from_seed(inout uint seed) {
   43 |         int k;
   44 |         int s = int(seed);
   45 |         if (s == 0)
   46 |         s = 305420679;
   47 |         k = s / 127773;
   48 |         s = 16807 * (s - k * 127773) - 2836 * k;
   49 |         if (s < 0)
   50 |                 s += 2147483647;
   51 |         seed = uint(s);
   52 |         return float(seed % uint(65536)) / 65535.0;
   53 | }
   54 | 
   55 | float rand_from_seed_m1_p1(inout uint seed) {
   56 |         return rand_from_seed(seed) * 2.0 - 1.0;
   57 | }
   58 | 
   59 | uint hash(uint x) {
   60 |         x = ((x >> uint(16)) ^ x) * uint(73244475);
   61 |         x = ((x >> uint(16)) ^ x) * uint(73244475);
   62 |         x = (x >> uint(16)) ^ x;
   63 |         return x;
   64 | }
   65 | 
   66 | void vertex() {
   67 |         uint base_number = NUMBER / uint(trail_divisor);
   68 |         uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);
   69 |         float angle_rand = rand_from_seed(alt_seed);
   70 |         float scale_rand = rand_from_seed(alt_seed);
   71 |         float hue_rot_rand = rand_from_seed(alt_seed);
   72 |         float anim_offset_rand = rand_from_seed(alt_seed);
   73 |         float pi = 3.14159;
   74 |         float degree_to_rad = pi / 180.0;
   75 | 
   76 |         int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));
   77 |         ivec2 emission_tex_size = textureSize(emission_texture_points, 0);
   78 |         ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);
   79 |         bool restart = false;
   80 |         float tv = 0.0;
   81 |         if (CUSTOM.y > CUSTOM.w) {
   82 |                 restart = true;
   83 |                 tv = 1.0;
   84 |         }
   85 | 
   86 |         if (RESTART || restart) {
   87 |                 float tex_linear_velocity = 0.0;
   88 |                 float tex_angle = 0.0;
   89 |                 float tex_anim_offset = 0.0;
   90 |                 float spread_rad = spread * degree_to_rad;
   91 |                 float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;
   92 |                 float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);
   93 |                 vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));
   94 |                 vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));
   95 |                 direction_yz.z = direction_yz.z / max(0.0001,sqrt(abs(direction_yz.z))); // better uniform distribution
   96 |                 vec3 spread_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);
   97 |                 vec3 direction_nrm = normalize(direction);
   98 |                 // rotate spread to direction
   99 |                 vec3 binormal = cross(vec3(0.0, 1.0, 0.0), direction_nrm);
  100 |                 if (length(binormal) < 0.0001) {
  101 |                         // direction is parallel to Y. Choose Z as the binormal.
  102 |                         binormal = vec3(0.0, 0.0, 1.0);
  103 |                 }
  104 |                 binormal = normalize(binormal);
  105 |                 vec3 normal = cross(binormal, direction_nrm);
  106 |                 spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;
  107 |                 VELOCITY = spread_direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);
  108 |                 float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);
  109 |                 CUSTOM.x = base_angle * degree_to_rad;
  110 |                 CUSTOM.y = 0.0;
  111 |                 CUSTOM.w = (1.0 - lifetime_randomness * rand_from_seed(alt_seed));
  112 |                 CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random);
  113 |                 TRANSFORM[3].xyz = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;
E 114->                 vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xyz;
  115 |                 vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
  116 |                 vec3 tangent = normalize(cross(v0, normal));
  117 |                 vec3 bitangent = normalize(cross(tangent, normal));
  118 |                 VELOCITY = mat3(tangent, bitangent, normal) * VELOCITY;
  119 |                 VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;
  120 |                 TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
  121 |         } else {
  122 |                 CUSTOM.y += DELTA / LIFETIME;
  123 |                 tv = CUSTOM.y / CUSTOM.w;
  124 |                 float tex_linear_velocity = 0.0;
  125 |                 float tex_angular_velocity = 0.0;
  126 |                 float tex_linear_accel = textureLod(linear_accel_texture, vec2(tv, 0.0), 0.0).r;
  127 |                 float tex_radial_accel = 0.0;
  128 |                 float tex_tangent_accel = 0.0;
  129 |                 float tex_damping = 0.0;
  130 |                 float tex_angle = 0.0;
  131 |                 float tex_anim_speed = 0.0;
  132 |                 float tex_anim_offset = 0.0;
  133 |                 vec3 force = gravity;
  134 |                 vec3 pos = TRANSFORM[3].xyz;
  135 |                 // apply linear acceleration
  136 |                 force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel + tex_linear_accel) * mix(1.0, rand_from_seed(alt_seed), linear_accel_random) : vec3(0.0);
  137 |                 // apply radial acceleration
  138 |                 vec3 org = EMISSION_TRANSFORM[3].xyz;
  139 |                 vec3 diff = pos - org;
  140 |                 force += length(diff) > 0.0 ? normalize(diff) * (radial_accel + tex_radial_accel) * mix(1.0, rand_from_seed(alt_seed), radial_accel_random) : vec3(0.0);
  141 |                 // apply tangential acceleration;
  142 |                 vec3 crossDiff = cross(normalize(diff), normalize(gravity));
  143 |                 force += length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel + tex_tangent_accel) * mix(1.0, rand_from_seed(alt_seed), tangent_accel_random)) : vec3(0.0);
  144 |                 // apply attractor forces
  145 |                 VELOCITY += force * DELTA;
  146 |                 // orbit velocity
  147 |                 if (damping + tex_damping > 0.0) {
  148 |                         float v = length(VELOCITY);
  149 |                         float damp = (damping + tex_damping) * mix(1.0, rand_from_seed(alt_seed), damping_random);
  150 |                         v -= damp * DELTA;
  151 |                         if (v < 0.0) {
  152 |                                 VELOCITY = vec3(0.0);
  153 |                         } else {
  154 |                                 VELOCITY = normalize(VELOCITY) * v;
  155 |                         }
  156 |                 }
  157 |                 float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);
  158 |                 base_angle += CUSTOM.y * LIFETIME * (angular_velocity + tex_angular_velocity) * mix(1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, angular_velocity_random);
  159 |                 CUSTOM.x = base_angle * degree_to_rad;
  160 |                 CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random) + CUSTOM.y * (anim_speed + tex_anim_speed) * mix(1.0, rand_from_seed(alt_seed), anim_speed_random);
  161 |         }
  162 |         float tex_scale = textureLod(scale_texture, vec2(tv, 0.0), 0.0).r;
  163 |         float tex_hue_variation = 0.0;
  164 |         float hue_rot_angle = (hue_variation + tex_hue_variation) * pi * 2.0 * mix(1.0, hue_rot_rand * 2.0 - 1.0, hue_variation_random);
  165 |         float hue_rot_c = cos(hue_rot_angle);
  166 |         float hue_rot_s = sin(hue_rot_angle);
  167 |         mat4 hue_rot_mat = mat4(vec4(0.299, 0.587, 0.114, 0.0),
  168 |                         vec4(0.299, 0.587, 0.114, 0.0),
  169 |                         vec4(0.299, 0.587, 0.114, 0.0),
  170 |                         vec4(0.000, 0.000, 0.000, 1.0)) +
  171 |                 mat4(vec4(0.701, -0.587, -0.114, 0.0),
  172 |                         vec4(-0.299, 0.413, -0.114, 0.0),
  173 |                         vec4(-0.300, -0.588, 0.886, 0.0),
  174 |                         vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_c +
  175 |                 mat4(vec4(0.168, 0.330, -0.497, 0.0),
  176 |                         vec4(-0.328, 0.035,  0.292, 0.0),
  177 |                         vec4(1.250, -1.050, -0.203, 0.0),
  178 |                         vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_s;
  179 |         COLOR = hue_rot_mat * textureLod(color_ramp, vec2(tv, 0.0), 0.0) * color_value;
  180 |         if (trail_divisor > 1) {
  181 |                 COLOR *= textureLod(trail_color_modifier, vec2(float(int(NUMBER) % trail_divisor) / float(trail_divisor - 1), 0.0), 0.0);
  182 |         }
  183 | 
  184 |         TRANSFORM[0].xyz = normalize(TRANSFORM[0].xyz);
  185 |         TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);
  186 |         TRANSFORM[2].xyz = normalize(TRANSFORM[2].xyz);
  187 |         float base_scale = tex_scale * mix(scale, 1.0, scale_random * scale_rand);
  188 |         if (base_scale < 0.000001) {
  189 |                 base_scale = 0.000001;
  190 |         }
  191 |         TRANSFORM[0].xyz *= base_scale;
  192 |         TRANSFORM[1].xyz *= base_scale;
  193 |         TRANSFORM[2].xyz *= base_scale;
  194 |         if (CUSTOM.y > CUSTOM.w) {              ACTIVE = false;
  195 |         }
  196 | }
  197 | 
  198 | 
SHADER ERROR: Redefinition of 'normal'
          at: (null) (:114)
ERROR: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
   at: getornull (./core/rid.h:149)
handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib64/libc.so.6(+0x3ac90) [0x7f60254cdc90] (??:0)
[2] RasterizerStorageGLES3::update_particles() (/home/akien/Projects/godot/godot-3.x/drivers/gles3/rasterizer_storage_gles3.cpp:6546)
[3] RasterizerStorageGLES3::update_dirty_resources() (/home/akien/Projects/godot/godot-3.x/drivers/gles3/rasterizer_storage_gles3.cpp:8276)
[4] RasterizerGLES3::begin_frame(double) (/home/akien/Projects/godot/godot-3.x/drivers/gles3/rasterizer_gles3.cpp:214 (discriminator 2))
[5] VisualServerRaster::draw(bool, double) (/home/akien/Projects/godot/godot-3.x/servers/visual/visual_server_raster.cpp:105 (discriminator 2))
[6] VisualServerWrapMT::draw(bool, double) (/home/akien/Projects/godot/godot-3.x/servers/visual/visual_server_wrap_mt.cpp:92)
[7] Main::iteration() (/home/akien/Projects/godot/godot-3.x/main/main.cpp:2162)
[8] OS_X11::run() (/home/akien/Projects/godot/godot-3.x/platform/x11/os_x11.cpp:3640)
[9] godot-3.x(main+0x109) [0x177682f] (/home/akien/Projects/godot/godot-3.x/platform/x11/godot_x11.cpp:57)
[10] /lib64/libc.so.6(__libc_start_main+0xcd) [0x7f60254ba7dd] (??:0)
[11] godot-3.x(_start+0x2a) [0x177667a] (??:?)
-- END OF BACKTRACE --
Aborted (core dumped)

That's likely due to #47310 which defined normal too. Renaming either variable should fix it. CC @mortarroad

It's worth noting that this specific MRP takes ages to generate the particles shape in 3.3.3-rc in my testing - but it does not crash, it just freezes for a couple minutes.

@akien-mga akien-mga added this to the 3.4 milestone Aug 9, 2021
@mortarroad
Copy link
Contributor

Yeah.

Or putting these into blocks (i.e. putting braces around them) should also work.
That would also make the intention clear, that these variables are only used as short lived temporaries.

@akien-mga
Copy link
Member

Fixed by #51553.

lekoder pushed a commit to KoderaSoftwareUnlimited/godot that referenced this issue Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants