Repository: godot
Issue: Canvas shaders with uniforms crash mobile renderer on Android, depending on order
Labels: bug,platform:android,topic:rendering,crash,topic:shaders

### Godot version

v4.1.1.stable.official [bd6af8e0e]

### System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 2060 (NVIDIA; 31.0.15.3623) - Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz (4 Threads)

### Issue description

Rendering a Sprite2D with a canvas_item shader that has uniforms declared, followed by a canvas_item that has no uniforms (including the default unassigned shader) is crashing the mobile renderer in Android on my Google Pixel 2 XL.

Maybe it's trying to apply the uniforms from the previous draw call to the next one? Something in the rendering state isn't getting reset properly.

The compatibility renderer works fine, and so does the mobile renderer in the editor on desktop.

The crash in ADB:
```
09-30 16:07:20.348 20823 20823 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
09-30 16:07:20.348 20823 20823 F DEBUG   : Cause: null pointer dereference
09-30 16:07:20.348 20823 20823 F DEBUG   :     x0  0000000000000000  x1  0000000000000000  x2  0000007b327d3280  x3  0000007c02859640
09-30 16:07:20.348 20823 20823 F DEBUG   :     x4  0000000000000001  x5  0000000000000000  x6  0000000000000001  x7  0000000000000001
09-30 16:07:20.348 20823 20823 F DEBUG   :     x8  0000000000000004  x9  0000000000000001  x10 0000007c327cc790  x11 0000000000000003
09-30 16:07:20.348 20823 20823 F DEBUG   :     x12 0000000000000000  x13 0000000000000001  x14 0000007b1287c9c0  x15 0000007c828f22f0
09-30 16:07:20.348 20823 20823 F DEBUG   :     x16 0000007a786a10a0  x17 0000000000000001  x18 0000007a77e18000  x19 0000007a786a0da0
09-30 16:07:20.348 20823 20823 F DEBUG   :     x20 0000000000000000  x21 0000000000000000  x22 0000007b22b0dd10  x23 0000000000008000
09-30 16:07:20.348 20823 20823 F DEBUG   :     x24 0000007b22b0dd10  x25 0000007bf2852d58  x26 0000000000000000  x27 0000000000000028
09-30 16:07:20.348 20823 20823 F DEBUG   :     x28 0000007a786a10a0  x29 0000007a786a3df0
09-30 16:07:20.348 20823 20823 F DEBUG   :     lr  00000007f9a6e000  sp  0000007a786a0470  pc  0000007a72d18cc8  pst 0000000000000000
09-30 16:07:20.532 20823 20823 F DEBUG   : backtrace:
09-30 16:07:20.532 20823 20823 F DEBUG   :       #00 pc 0000000000094cc8  /vendor/lib64/hw/vulkan.adreno.so (!!!0000!8fc203f72276cff568aecfb05c6306!e883189!+9016) (BuildId: 72db396c8baadb530a02baef5c3b344a)
09-30 16:07:20.532 20823 20823 F DEBUG   :       #01 pc 000000000004bb4c  /vendor/lib64/hw/vulkan.adreno.so (qglinternal::vkCmdDrawIndexed(VkCommandBuffer_T*, unsigned int, unsigned int, unsigned int, int, unsigned int)+284) (BuildId: 72db396c8baadb530a02baef5c3b344a)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #02 pc 00000000015cbde0  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #03 pc 0000000002b39694  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #04 pc 0000000002b3c1c0  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #05 pc 0000000002b3d060  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #06 pc 0000000002a804f0  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #07 pc 0000000002a82d28  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #08 pc 0000000002a771e0  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #09 pc 0000000002a78490  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #10 pc 0000000002a29928  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #11 pc 0000000000c3bb24  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #12 pc 0000000000bfa81c  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so
09-30 16:07:20.533 20823 20823 F DEBUG   :       #13 pc 0000000000c0e75c  /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/lib/arm64/libgodot_android.so (Java_org_godotengine_godot_GodotLib_step+220)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #14 pc 000000000013ced4  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #15 pc 00000000001337e8  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #16 pc 00000000001a9804  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+228) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #17 pc 000000000031c040  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #18 pc 0000000000312228  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+912) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #19 pc 000000000068861c  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+548) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #20 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #21 pc 00000000000251bc  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/base.apk!classes2.dex] (org.godotengine.godot.vulkan.VkRenderer.onVkDrawFrame)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #22 pc 0000000000685960  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1520) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #23 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #24 pc 0000000000025a94  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~VPzB_QESfse502o8siHF7w==/org.godotengine.test-A3OTzWRR077vAPM-ntEedA==/base.apk!classes2.dex] (org.godotengine.godot.vulkan.VkThread.run+300)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #25 pc 00000000003094d0  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.7618685802058321727)+264) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #26 pc 00000000006740c0  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+776) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #27 pc 000000000013cff8  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #28 pc 0000000000133564  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #29 pc 00000000001a97e8  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #30 pc 000000000055c384  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+460) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #31 pc 00000000005ac204  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1308) (BuildId: d0f321775158ed00df284edfabf672b6)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #32 pc 00000000000b0758  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: c78cdff5b820a550771130d6bde95081)
09-30 16:07:20.533 20823 20823 F DEBUG   :       #33 pc 0000000000050150  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: c78cdff5b820a550771130d6bde95081)
```


### Steps to reproduce

- Add a Sprite2D node, with a canvas_item shader declaring a uniform.
- Add a second sprite with the default settings, or using another shader with no uniforms.
- Move the second sprite to a lower rendering order in the scene tree, or give it a higher z-index.
- The Android build closes abruptly on the next frame.

### Minimal reproduction project

[UniformTestProject.zip](https://github.com/godotengine/godot/files/12775801/UniformTestProject.zip)