utopia-rise / fmod-gdextension

FMOD Studio GDExtension bindings for the Godot game engine
MIT License
385 stars 42 forks source link

fix return-stack-address violations #143

Closed ChibiDenDen closed 1 year ago

ChibiDenDen commented 1 year ago

While building the project, the following warning appears multiple times:

../godot-cpp/include/core/Godot.hpp:163:10: warning: returning reference to local temporary object [-Wreturn-stack-address] return a; ^ ../godot-cpp/include/core/Godot.hpp:285:34: note: in instantiation of member function 'godot::_ArgCast<const godot::Array &>::_arg_cast' requested here ret = (obj->f)(_ArgCast::_arg_cast(args[I])...); ^ ../godot-cpp/include/core/Godot.hpp:310:10: note: in instantiation of function template specialization 'godot::_WrappedMethod<godot::Fmod, float, unsigned long, const godot::Array &>::apply<0, 1>' requested here method->apply(var, obj, arg, typename construct_sequence<sizeof...(As)>::type{}); ^ ../godot-cpp/include/core/Godot.hpp:325:34: note: in instantiation of function template specialization 'godot::__wrapped_method<godot::Fmod, float, unsigned long, const godot::Array &>' requested here return (godot_wrapper_method)&wrappedmethod<T, R, As...>; ^ ../godot-cpp/include/core/Godot.hpp:343:42: note: in instantiation of function template specialization 'godot::get_wrapper_function<godot::Fmod, float, unsigned long, const godot::Array &>' requested here method.method = (__godot_wrapper_method)___get_wrapper_function(method_ptr); ^ ./src/godot_fmod.cpp:47:5: note: in instantiation of function template specialization 'godot::register_method<float (godot::Fmod::)(unsigned long, const godot::Array &)>' requested here register_method("get_event_parameter_by_id", &Fmod::get_event_parameter_by_id); ^

This is due to register_method not handling const references and instead returning a reference to a temporary stack variable.

This causes crashes on android on most API's as variants are not passed correctly.

Fixed and verified on android armv8

CedNaru commented 1 year ago

Do you have a log of the android crash ? I tested Android many times and never got one.

ChibiDenDen commented 1 year ago

@CedNaru I tested with godot 3.5.1 if it means anything, it works fine on windows but crashes on android when calling "play_one_shot"

Ill reproduce later today and provide logcat output if it helps. The fix itself does fix a memory bug in the existing c++ code that I think should be addressed regardless.

ChibiDenDen commented 1 year ago

relevant logcat output from the second of the crash:

12-08 19:16:29.659 31554 31615 I godot : Playing fmod event event:/UI/UIButton 12-08 19:16:29.660 31554 31615 F libc : Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xb400006ffffffff8 in tid 31615 (GLThread 51), pid 31554 (om.cdd.dd) 12-08 19:16:29.746 672 672 I tombstoned: received crash request for pid 31615 12-08 19:16:29.747 32059 32059 I crash_dump64: performing dump of process 31554 (target tid = 31615) 12-08 19:16:29.970 32059 32059 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 12-08 19:16:29.970 32059 32059 F DEBUG : Build fingerprint: 'google/raven/raven:13/TQ1A.221205.011/9244662:user/release-keys' 12-08 19:16:29.970 32059 32059 F DEBUG : Revision: 'MP1.0' 12-08 19:16:29.970 32059 32059 F DEBUG : ABI: 'arm64' 12-08 19:16:29.970 32059 32059 F DEBUG : Timestamp: 2022-12-08 19:16:29.751830434+0200 12-08 19:16:29.970 32059 32059 F DEBUG : Process uptime: 7s 12-08 19:16:29.970 32059 32059 F DEBUG : Cmdline: com.cdd.dd 12-08 19:16:29.970 32059 32059 F DEBUG : pid: 31554, tid: 31615, name: GLThread 51 >>> com.cdd.dd <<< 12-08 19:16:29.970 32059 32059 F DEBUG : uid: 10320 12-08 19:16:29.970 32059 32059 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) 12-08 19:16:29.970 32059 32059 F DEBUG : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xb400006ffffffff8 12-08 19:16:29.970 32059 32059 F DEBUG : x0 0000006fb6ff9b28 x1 0000006fb6ff9c00 x2 0000006fb773319c x3 0000000000000000 12-08 19:16:29.970 32059 32059 F DEBUG : x4 0000006fb6ff9e98 x5 0000006fb6ffa018 x6 4148542e48542e39 x7 7f7f7f7f7f7f7f7f 12-08 19:16:29.970 32059 32059 F DEBUG : x8 b400006ffffffff8 x9 0000000000000004 x10 0000000000000000 x11 0000000000000017 12-08 19:16:29.970 32059 32059 F DEBUG : x12 0000000000000004 x13 0000000000000004 x14 0000000000000064 x15 0000006fb6ff9e50 12-08 19:16:29.970 32059 32059 F DEBUG : x16 0000006f9673a190 x17 0000006f965e6850 x18 0000006fb654e000 x19 b4000071211474e0 12-08 19:16:29.970 32059 32059 F DEBUG : x20 0000000000000000 x21 0000000000000001 x22 0000006fb6ff9c00 x23 b4000071211476a8 12-08 19:16:29.970 32059 32059 F DEBUG : x24 b4000070611bb330 x25 0000006fb6ffd000 x26 0000006fb6ffd000 x27 b4000070e110cfa0 12-08 19:16:29.970 32059 32059 F DEBUG : x28 0000000000000002 x29 0000006fb6ff9b50 12-08 19:16:29.970 32059 32059 F DEBUG : lr 0000006f965df2dc sp 0000006fb6ff9b10 pc 0000006fb77331c0 pst 0000000080001000 12-08 19:16:29.970 32059 32059 F DEBUG : backtrace: 12-08 19:16:29.970 32059 32059 F DEBUG : #00 pc 00000000007321c0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #01 pc 00000000001df2d8 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libGodotFmod.android.release.arm64-v8a.so (godot::Fmod::_create_instance(godot::String const&, bool, godot::Node*)+64) (BuildId: 13b7272e00f44a4239d38b4720eb2124a2cfa85b) 12-08 19:16:29.970 32059 32059 F DEBUG : #02 pc 00000000001d7f3c /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libGodotFmod.android.release.arm64-v8a.so (godot::Fmod::play_one_shot(godot::String const&, godot::Node*)+32) (BuildId: 13b7272e00f44a4239d38b4720eb2124a2cfa85b) 12-08 19:16:29.970 32059 32059 F DEBUG : #03 pc 00000000001e3d50 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libGodotFmod.android.release.arm64-v8a.so (void godot::_WrappedMethod<godot::Fmod, void, godot::String const&, godot::Node*>::apply<0, 1>(godot::Variant*, godot::Fmod*, godot::Variant**, godot::__Sequence<0, 1>)+192) (BuildId: 13b7272e00f44a4239d38b4720eb2124a2cfa85b) 12-08 19:16:29.970 32059 32059 F DEBUG : #04 pc 000000000071dd90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #05 pc 0000000001988d90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #06 pc 0000000001a1bdcc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #07 pc 00000000007db618 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #08 pc 0000000001988d90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #09 pc 0000000001a1bdcc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #10 pc 00000000007db618 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #11 pc 0000000001988d90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #12 pc 0000000001a1bdcc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #13 pc 00000000007db618 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #14 pc 0000000001988d90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #15 pc 0000000001a1bdcc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #16 pc 00000000007db618 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #17 pc 0000000001988d90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #18 pc 000000000198abe0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #19 pc 0000000001989564 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #20 pc 0000000000ccf014 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #21 pc 0000000000ccebf4 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #22 pc 0000000000cce734 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #23 pc 0000000000cd4790 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #24 pc 0000000001987d54 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #25 pc 0000000001988cbc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #26 pc 0000000000cab3b0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #27 pc 0000000000cac2e4 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #28 pc 0000000000ca9dac /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #29 pc 0000000000ca9b84 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #30 pc 0000000000cc4ee0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #31 pc 0000000001988e38 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #32 pc 0000000001988be4 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #33 pc 0000000000c82c90 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #34 pc 0000000000c83cfc /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #35 pc 00000000005f735c /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #36 pc 00000000005f7818 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #37 pc 00000000005f8cd0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #38 pc 000000000060f0f0 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #39 pc 00000000005d29ec /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so 12-08 19:16:29.970 32059 32059 F DEBUG : #40 pc 00000000005df568 /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/lib/arm64/libgodot_android.so (Java_org_godotengine_godot_GodotLib_step+212) 12-08 19:16:29.970 32059 32059 F DEBUG : #41 pc 0000000000440554 /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #42 pc 0000000000209398 /apex/com.android.art/lib64/libart.so (nterp_helper+152) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #43 pc 0000000000184ec8 [anon:dalvik-classes.dex extracted in memory from /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/base.apk] (org.godotengine.godot.GodotRenderer.onDrawFrame+20) 12-08 19:16:29.970 32059 32059 F DEBUG : #44 pc 000000000020b074 /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #45 pc 0000000000189086 [anon:dalvik-classes.dex extracted in memory from /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/base.apk] (org.godotengine.godot.gl.GLSurfaceView$GLThread.guardedRun+986) 12-08 19:16:29.970 32059 32059 F DEBUG : #46 pc 000000000020a254 /apex/com.android.art/lib64/libart.so (nterp_helper+3924) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #47 pc 000000000018965c [anon:dalvik-classes.dex extracted in memory from /data/app/~~Mg3CH2XOwyoApwh58Z-PNA==/com.cdd.dd-xTjGP7pFXTYaDbIp7lAlzQ==/base.apk] (org.godotengine.godot.gl.GLSurfaceView$GLThread.run+48) 12-08 19:16:29.970 32059 32059 F DEBUG : #48 pc 0000000000436b6c /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+556) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #49 pc 0000000000468938 /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+156) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #50 pc 0000000000468620 /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+388) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #51 pc 0000000000618214 /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1668) (BuildId: d307dc6adc4105b5e392ad710770385d) 12-08 19:16:29.970 32059 32059 F DEBUG : #52 pc 00000000000c15dc /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+204) (BuildId: 1154186c46119a81daca3db1a6b68111) 12-08 19:16:29.970 32059 32059 F DEBUG : #53 pc 0000000000054a30 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 1154186c46119a81daca3db1a6b68111) 12-08 19:16:29.984 672 672 E tombstoned: Tombstone written to: tombstone_13 gdscript code used to play the event:

fun play_sound(name): var event_name = "event:/" + name if not Fmod.check_event_path(event_name): return print("Playing fmod event " + event_name) Fmod.play_one_shot(event_name, null) you can see my print "Playing fmod event" right before the crash

using play_one_shot_with_params will not crash, but instead print the following message (without playing a sound):

12-08 19:21:52.865 5412 5452 I godot : Playing fmod event event:/UI/UIButton 12-08 19:21:52.865 5412 5452 E godot : ERROR: FMOD Sound System: cannot find in ##cont collection. 12-08 19:21:52.865 5412 5452 E godot : at: FMOD::Studio::EventInstance *godot::Fmod::_create_instance(const godot::String &, bool, godot::Node *) (./src/godot_fmod.cpp:1214) - FMOD Sound System: cannot find in ##cont collection. you can see my print "Playing fmod event" right before the call with a proper event name, but in the fmod plugin, the string is empty.

CedNaru commented 1 year ago

I never knew that registering const ref in Godot methods was ending up in that kind of issue (magic of C++ templates, I guess). But I see no issue with applying the changes. @bitbrain no need to pick that one for 4.0. From what I see, they added code to properly handle references and const references in the new version. It seems that it even became the standard.

bitbrain commented 1 year ago

@CedNaru good stuff. I see the builds are failing - probably still due to https://github.com/utopia-rise/fmod-gdnative/issues/95?

CedNaru commented 1 year ago

Yeah, don't know how to solve that. It seems that even having the person adding secrets on their own doesn't work.