godotengine / godot

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

HTTPRequest crash on android when requesting image with mbedTLS module disabled #59672

Open Myran opened 2 years ago

Myran commented 2 years ago

Godot version

3.4.4 stable - 419e713a29f20bd3351a54d1e6c4c5af7ef4b253

System information

Galaxy S9, SM-G960F

Issue description

Attempting to retrieve an image using HTTPRequest works fine in editor (MacOS) and on iOS however it crashes on android device. Tried with different images with no success

Retrieving a json as in documentation example works on perfectly on android, in editor and on iOS.

func test():
    var http_request = HTTPRequest.new()
    add_child(http_request)
    #http_request.connect("request_completed", self, "_on_request_completed")
    http_request.request("https://dummyimage.com/600x400/000/fff.png&text=test")
2022-03-29 14:46:32.078 7066-7066/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-03-29 14:46:32.078 7066-7066/? A/DEBUG: Build fingerprint: 'samsung/starltexx/starlte:10/QP1A.190711.020/G960FXXUHFVB4:user/release-keys'
2022-03-29 14:46:32.078 7066-7066/? A/DEBUG: Revision: '26'
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: ABI: 'arm64'
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: Timestamp: 2022-03-29 14:46:32+0200
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: pid: 6382, tid: 6609, name: GLThread 3233  >>> org.primaryhive.gameone <<<
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: uid: 10848
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x100
2022-03-29 14:46:32.079 7066-7066/? A/DEBUG: Cause: null pointer dereference
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x0  0000000000000000  x1  0000000000000000  x2  0000000000000031  x3  8dcb8c0b8c0b8000
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x4  0000006eae35d995  x5  191e1f0200030200  x6  00020300021f1e19  x7  362d30312d332f30
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x8  0000000000000000  x9  0000000000000000  x10 0000006eedb0467c  x11 0000000000000038
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x12 0000000000000005  x13 0000006ef4a72e10  x14 00000000ffffffff  x15 0000000000000000
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x16 0000007001b14378  x17 0000007003c98ba0  x18 0000006eead28000  x19 0000006ec78076d0
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x20 0000006ec7807830  x21 0000000000000000  x22 0000006ef4a74020  x23 0000006eecd0bff4
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x24 0000006ef4a74020  x25 0000000000000019  x26 0000006eee0ad000  x27 0000006ef4a74020
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     x28 0000006ef4e86c10  x29 0000006ef4a72970
2022-03-29 14:46:32.080 7066-7066/? A/DEBUG:     sp  0000006ef4a728a0  lr  0000006eedb047ec  pc  0000006eedb594f8

2022-03-29 14:46:32.239 7066-7066/? A/DEBUG: backtrace:
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #00 pc 00000000010554f8  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #01 pc 00000000010007e8  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #02 pc 0000000000596eac  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #03 pc 0000000000597e44  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #04 pc 000000000059ae30  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #05 pc 0000000000ed1cfc  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #06 pc 00000000005c3d3c  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #07 pc 00000000005c3f28  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.239 7066-7066/? A/DEBUG:       #08 pc 00000000001ce9d4  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #09 pc 00000000001a259c  /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/lib/arm64/libgodot_android.so (Java_org_godotengine_godot_GodotLib_step+192)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #10 pc 0000000000141350  /apex/com.android.runtime/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #11 pc 00000000001385b8  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #12 pc 00000000001470cc  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+276) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #13 pc 00000000002eb4f8  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #14 pc 00000000002e6584  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+900) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #15 pc 00000000005ad918  /apex/com.android.runtime/lib64/libart.so (MterpInvokeStatic+368) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #16 pc 0000000000132994  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #17 pc 000000000011a82c  [anon:dalvik-classes5.dex extracted in memory from /data/app/org.primaryhive.gameone-ehcI4mezxc2yKyT-RlfLrA==/base.apk!classes5.dex] (org.godotengine.godot.GodotRenderer.onDrawFrame+20)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #18 pc 00000000005ac874  /apex/com.android.runtime/lib64/libart.so (MterpInvokeInterface+1740) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.240 7066-7066/? A/DEBUG:       #19 pc 0000000000132a14  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #20 pc 000000000032cd86  /system/framework/framework.jar (android.opengl.GLSurfaceView$GLThread.guardedRun+1086)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #21 pc 00000000005ad410  /apex/com.android.runtime/lib64/libart.so (MterpInvokeDirect+1168) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #22 pc 0000000000132914  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #23 pc 000000000032d3a8  /system/framework/framework.jar (android.opengl.GLSurfaceView$GLThread.run+88)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #24 pc 00000000002bbe28  /apex/com.android.runtime/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.5467380822148485331+240) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #25 pc 000000000059c210  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1024) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #26 pc 0000000000141468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #27 pc 0000000000138334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #28 pc 00000000001470ac  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #29 pc 00000000004bad28  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #30 pc 00000000004bbdd8  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #31 pc 00000000004fc9f0  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176) (BuildId: 0680f97b9649cf08862df1e69e76e0f3)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #32 pc 00000000000e3b24  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 3f350ca06c3b80560f65755286daf320)
2022-03-29 14:46:32.241 7066-7066/? A/DEBUG:       #33 pc 0000000000085330  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 3f350ca06c3b80560f65755286daf320)

Steps to reproduce

Run test function on android device

Minimal reproduction project

No response

Atem1995 commented 2 years ago

Make sure your link for image is useful. delete "&text=test" My test code on Android is working well. Just check your code or the export setting,When exporting to Android, make sure to enable the INTERNET permission in the Android export

func _ready():
    # Create an HTTP request node and connect its completion signal.
    var http_request = HTTPRequest.new()
    add_child(http_request)
    http_request.connect("request_completed", self, "_http_request_completed")

    # Perform the HTTP request. The URL below returns a PNG image as of writing.
    var error = http_request.request("https://via.placeholder.com/512")
    if error != OK:
        push_error("An error occurred in the HTTP request.")

# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
    var image = Image.new()
    var error = image.load_png_from_buffer(body)
    if error != OK:
        push_error("Couldn't load the image.")

    var texture = ImageTexture.new()
    texture.create_from_image(image)

    # Display the image in a TextureRect node.
    var texture_rect = TextureRect.new()
    add_child(texture_rect)
    texture_rect.texture = texture
Myran commented 2 years ago

Make sure your link for image is useful. delete "&text=test" My test code on Android is working well. Just check your code or the export setting,When exporting to Android, make sure to enable the INTERNET permission in the Android export

The image request works using editor and on iOS and I get the crash with any image only on android. The request works with regular json target on android and INTERNET permission is enabled.

This example crashes the same way for me. I will try to get ahold of another android phone to rule out the device

func _ready():
    # Create an HTTP request node and connect its completion signal.
    var http_request = HTTPRequest.new()
    add_child(http_request)
    http_request.connect("request_completed", self, "_http_request_completed")

    # Perform the HTTP request. The URL below returns a PNG image as of writing.
    var error = http_request.request("https://via.placeholder.com/512")
    if error != OK:
      push_error("An error occurred in the HTTP request.")

# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
    var image = Image.new()
    var error = image.load_png_from_buffer(body)
    if error != OK:
      push_error("Couldn't load the image.")

    var texture = ImageTexture.new()
    texture.create_from_image(image)

    # Display the image in a TextureRect node.
    var texture_rect = TextureRect.new()
    add_child(texture_rect)
    texture_rect.texture = texture
Atem1995 commented 2 years ago

I'm not sure if it's related to your Android SDK version or others.  you can try to export other Android applications and have a test to run normally without http request node.

---Original--- From: @.> Date: Wed, Mar 30, 2022 04:41 AM To: @.>; Cc: "吾也君( Atem @.**@.>; Subject: Re: [godotengine/godot] HTTPRequest crash on android when requesting image (Issue #59672)

Make sure your link for image is useful. delete "&text=test" My test code on Android is working well. Just check your code or the export setting,When exporting to Android, make sure to enable the INTERNET permission in the Android export

The image request works using editor and on iOS and I get the crash with any image only on android. The request works with regular json target on android and INTERNET permission is enabled.

This example crashes the same way for me. I will try to get ahold of another android phone to rule out the device func _ready(): # Create an HTTP request node and connect its completion signal. var http_request = HTTPRequest.new() add_child(http_request) http_request.connect("request_completed", self, "_http_request_completed") # Perform the HTTP request. The URL below returns a PNG image as of writing. var error = http_request.request("https://via.placeholder.com/512") if error != OK: push_error("An error occurred in the HTTP request.") # Called when the HTTP request is completed. func _http_request_completed(result, response_code, headers, body): var image = Image.new() var error = image.load_png_from_buffer(body) if error != OK: push_error("Couldn't load the image.") var texture = ImageTexture.new() texture.create_from_image(image) # Display the image in a TextureRect node. var texture_rect = TextureRect.new() add_child(texture_rect) texture_rect.texture = texture
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Myran commented 2 years ago

Also crashes the same way on a ASUS Chromebook C302CA

Myran commented 2 years ago

Found the issue

I am building the android export using the following optimization as shown in the documentation:

scons platform=android target=release_debug android_arch=armv7 --jobs=$(sysctl -n hw.logicalcpu) module_bmp_enabled=no module_bullet_enabled=no module_csg_enabled=no module_dds_enabled=no module_enet_enabled=no module_etc_enabled=no module_gdnative_enabled=no module_gridmap_enabled=no module_hdr_enabled=no module_mbedtls_enabled=no module_mobile_vr_enabled=no module_opus_enabled=no module_pvr_enabled=no module_recast_enabled=no module_regex_enabled=no module_squish_enabled=no module_tga_enabled=no module_thekla_unwrap_enabled=no module_theora_enabled=no module_tinyexr_enabled=no module_vorbis_enabled=no module_webm_enabled=no module_websocket_enabled=no disable_advanced_gui=no disable_3d=yes optimize=size use_lto=yes

The crash goes away once I build with all modules so one of them is required however Its not obvious for me which one is required for images trough HTTPRequest. Is it possible to list dependencies on each module somehow?

Zireael07 commented 2 years ago

Hm, try enabling them one by one? (Starting with tinyexr, etc, websockets, mbedtls and dds, so things related to either the net or images. I think Bullet and CSG can be safely ruled out as not being the cause)

Myran commented 2 years ago

Found it:

module_mbedtls_enabled=yes

is required to not crash when requesting an image trought HTTPRequest. I had accidentaly disabled all optimizations for iOS which made it work on the ipad and that made me rule out the optimizations early.

I am not familiar with mbedtls so I dont know if this is a bug or correct behaviour

akien-mga commented 2 years ago

It's normal that HTTPS request wouldn't work without mbedTLS, which is the module that provides support for SSL/TLS (the "S" in HTTPS).

But it shouldn't crash, instead it should throw an error, so that's still something that needs to be fixed in the engine.