godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.19k stars 20.22k forks source link

GPU Particles causing constant crashes on some Android devices #80331

Open SirTodd opened 1 year ago

SirTodd commented 1 year ago

Godot version

4.1.1 stable

System information

Android, GLES3

Issue description

I have been getting constant reports of crashes coming from very specific devices. All devices are low-end, having a Mediatek MT6769/MT6833V or some other variations of chipsets, as well as a few Samsung Exynos 850. They also have between 2GB-4GB ram. I have thousands of players, and all the reports come from these specific devices, even clearing the app data and uninstalling does not solve it.

All stack trace look very similar

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 5286 >>> com.enigmadev.uploadsimulator2 <<<

backtrace:
  #00  pc 0x0000000001338530  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so
  #01  pc 0x0000000003316480  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so
  #02  pc 0x00000000013b7950  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so
  #03  pc 0x00000000006e28dc  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so
  #04  pc 0x0000000000690108  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so
  #05  pc 0x00000000006a9284  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/split_config.armeabi_v7a.apk!libgodot_android.so (Java_org_godotengine_godot_GodotLib_step+228)
  #06  pc 0x00000000003c1b9d  /apex/com.android.art/lib/libart.so (art_quick_generic_jni_trampoline+44)
  #07  pc 0x000000000201c3cd  /memfd:jit-cache (org.godotengine.godot.gl.GodotRenderer.onDrawFrame+100)
  #08  pc 0x00000000000f179c  /apex/com.android.art/lib/libart.so (nterp_helper+5388)
  #09  pc 0x000000000072794a  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/oat/arm/base.vdex (org.godotengine.godot.gl.GLSurfaceView$GLThread.guardedRun+896)
  #10  pc 0x00000000000f0d80  /apex/com.android.art/lib/libart.so (nterp_helper+2800)
  #11  pc 0x0000000000727cf4  /data/app/~~WpD4_MuKLIBBZgSvYpeh_g==/com.enigmadev.uploadsimulator2-uXGWD8zDEi4QWMncYdyZjg==/oat/arm/base.vdex (org.godotengine.godot.gl.GLSurfaceView$GLThread.run+48)
  #12  pc 0x00000000003bd1d5  /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68)
  #13  pc 0x00000000003bcc77  /apex/com.android.art/lib/libart.so (void art::quick_invoke_reg_setup<false>(art::ArtMethod*, unsigned int*, unsigned int, art::Thread*, art::JValue*, char const*) (.__uniq.192663596067446536341070919852553954320.llvm.16200230356545185596)+158)
  #14  pc 0x000000000028a4c5  /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+136)
  #15  pc 0x0000000000313969  /apex/com.android.art/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*) (.__uniq.245181933781456475607640333933569312899.llvm.2586733929373010981)+40)
  #16  pc 0x0000000000313875  /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+164)
  #17  pc 0x000000000033a3af  /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+42)
  #18  pc 0x00000000002f0625  /apex/com.android.art/lib/libart.so (art::Thread::CreateCallback(void*)+416)
  #19  pc 0x00000000000ade0b  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
  #20  pc 0x0000000000063e73  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)

This issue persist with 4.0.3 as well.

Steps to reproduce

Cannot provide.

Minimal reproduction project

Cannot provide.

AThousandShips commented 1 year ago

Without any information about the nature of the project that is crashing I'm not sure anything can be done, unless there's some hardware specific error that can be pinned down

SirTodd commented 1 year ago

I will try to gather more information. All I know for now is that it happens when the game runs get_tree().reload_current_scene()

AThousandShips commented 1 year ago

Possibly related to:

SirTodd commented 1 year ago

Actually, it is not related to reload_current_scene(), the crashes were happening as soon as any GPUParticles2D played. Weirdly enough, it was working before a game update, and this update did not change the engine version nor did make changes to the particles, so I don't know what is going on there. Maybe some shader cache issue?

clayjohn commented 1 year ago

Actually, it is not related to reload_current_scene(), the crashes were happening as soon as any GPUParticles2D played. Weirdly enough, it was working before a game update, and this update did not change the engine version nor did make changes to the particles, so I don't know what is going on there. Maybe some shader cache issue?

Likely not a shader cache issue if you can reproduce in 4.0.3. Shader caching was implemented in 4.1.

The stack trace doesn't appear to be anything related to rendering, but its impossible to say with the limited amount of information.

What changes did you make in the update that introduced the crash?

SirTodd commented 1 year ago

Actually, it is not related to reload_current_scene(), the crashes were happening as soon as any GPUParticles2D played. Weirdly enough, it was working before a game update, and this update did not change the engine version nor did make changes to the particles, so I don't know what is going on there. Maybe some shader cache issue?

Likely not a shader cache issue if you can reproduce in 4.0.3. Shader caching was implemented in 4.1.

The stack trace doesn't appear to be anything related to rendering, but its impossible to say with the limited amount of information.

What changes did you make in the update that introduced the crash?

There were many new content in this update, but all done in gdscript and no plugins updates, I don't see how that could affect just specific phones. At this point I don't even know what is the cause, it seems completely random, although it is always after reloading the scene. I can't even debug it myself, since I don't have any of these phones, so I have to rely on user reports and stack trace.

Here is another crash from one of my users Screenshot_20230813-143643

SirTodd commented 1 year ago

Actually, it is not related to reload_current_scene(), the crashes were happening as soon as any GPUParticles2D played. Weirdly enough, it was working before a game update, and this update did not change the engine version nor did make changes to the particles, so I don't know what is going on there. Maybe some shader cache issue?

Likely not a shader cache issue if you can reproduce in 4.0.3. Shader caching was implemented in 4.1.

The stack trace doesn't appear to be anything related to rendering, but its impossible to say with the limited amount of information.

What changes did you make in the update that introduced the crash?

After making some reworks to the game code and avoiding reload_current_scene(), all the issues were gone. However, I added a new scene to the game that is only instantiated when clicking on a button. Inside this scene it contains a GpuParticles2D. It also uses an animation material. The same users started reporting crashes when opening this same scene, but only after the second time opening it. There is nothing in this scene that could be causing crashes, and since it only crashes the second time opening it, I suspect it is related to shader caching.

This crash only affects older phones, and just some of them, so most likely bad opengl implementation by manufacturers. But there should be a workaround for this. I am using cpu particles everywhere in the project now, but cpu particles don't support ring emission shape, which is exactly why I used gpu particles.

Calinou commented 1 year ago

I am using cpu particles everywhere in the project now, but cpu particles don't support ring emission shape, which is exactly why I used gpu particles.

According to https://github.com/godotengine/godot/pull/50370, ring emission shape is supported in CPUParticles3D.

flotos commented 10 months ago

I have the same problem and it happens only for particles using a texture. If I remove my texture (a 64x64 png) my game stop crashing.

Here is the content added to my scene from the git diff that introduces the crash:

[ext_resource type="Texture2D" uid="uid://dw2pg51ck2t17" path="res://sprites/particles/leaf.png" id="10_a34ho"]

[node name="Leaves" type="GPUParticles2D" parent="."]
position = Vector2(119, 325)
amount = 4
process_material = SubResource("ParticleProcessMaterial_dospk")
texture = ExtResource("10_a34ho")
lifetime = 5.0
trail_lifetime = 0.4
trail_sections = 4
[sub_resource type="Gradient" id="Gradient_tlwpa"]
offsets = PackedFloat32Array(0.0114943, 0.273381, 0.71223, 1)
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_k68vj"]
gradient = SubResource("Gradient_tlwpa")

[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_dospk"]
lifetime_randomness = 0.5
emission_shape = 3
emission_box_extents = Vector3(300, 150, 1)
particle_flag_disable_z = true
gravity = Vector3(50, 10, 0)
initial_velocity_min = 20.0
initial_velocity_max = 50.0
angular_velocity_min = 500.0
angular_velocity_max = 500.0
orbit_velocity_min = -0.03
orbit_velocity_max = 0.03
linear_accel_min = 10.0
linear_accel_max = 500.0
scale_min = 0.3
scale_max = 0.8
color = Color(0.85098, 0.521569, 0.607843, 1)
color_ramp = SubResource("GradientTexture1D_k68vj")
turbulence_enabled = true
turbulence_noise_speed_random = 0.5
Ayush-Agarwal123 commented 6 months ago

I am having a similar issue the build is crashing on some low end android devices, and I can confirm that it is due to a shader. I have a shader to slightly tilt a card, once I take out a build without this shader the crash is gone. I am very new at shader programming so I am not sure if there is something wrong with my shader.

Here is my shader code:

shader_type canvas_item;

uniform float fov : hint_range(0, 359) = 90;
uniform bool cull_back = true;
uniform float y_rot : hint_range(-360, 360) = 0.0;
uniform float x_rot : hint_range(-360, 360) = 0.0;
uniform float inset : hint_range(-100, 100) = 0.0;
uniform vec4 tint_color : source_color;

varying flat vec2 o;
varying vec3 p;

void vertex() {
    float sin_b = sin(y_rot / 180.0 * PI);
    float cos_b = cos(y_rot / 180.0 * PI);
    float sin_c = sin(x_rot / 180.0 * PI);
    float cos_c = cos(x_rot / 180.0 * PI);

    mat3 inv_rot_mat;
    inv_rot_mat[0][0] = cos_b;
    inv_rot_mat[0][1] = 0.0;
    inv_rot_mat[0][2] = -sin_b;

    inv_rot_mat[1][0] = sin_b * sin_c;
    inv_rot_mat[1][1] = cos_c;
    inv_rot_mat[1][2] = cos_b * sin_c;

    inv_rot_mat[2][0] = sin_b * cos_c;
    inv_rot_mat[2][1] = -sin_c;
    inv_rot_mat[2][2] = cos_b * cos_c;

    float t = tan(fov / 360.0 * PI);
    p = inv_rot_mat * vec3((UV - 0.5), 0.5 / t);
    float v = (0.5 / t) + 0.5;
    p.xy *= v * inv_rot_mat[2].z;
    o = v * inv_rot_mat[2].xy;

    VERTEX += (UV - 0.5) / TEXTURE_PIXEL_SIZE * t * (1.0 - inset);
}

void fragment() {
    if (cull_back && p.z <= 0.0) discard;
    vec2 uv = (p.xy / p.z).xy - o;
    vec4 texture_color = texture(TEXTURE, uv + 0.5);
    // Apply tint color
    texture_color *= tint_color;
    // Apply alpha mask
    texture_color.a *= step(max(abs(uv.x), abs(uv.y)), 0.5);
    COLOR = texture_color;
}
Calinou commented 5 months ago

@Ayush-Agarwal123 This is an unrelated issue, as this issue is about particles. That said, you may want to check that your shader will never perform a division by zero, which may crash graphics drivers on certain devices.

clayjohn commented 5 months ago

This issue may be fixed by https://github.com/godotengine/godot/pull/88816