Android NDK:无法调用C++构造函数

fv2wmkja  于 2024-01-09  发布在  Android
关注(0)|答案(1)|浏览(208)

我正在尝试使用NDK将一个C++桌面程序移植到Android上。当我重新启动时,我发现在初始化类Windows时没有调用类Constants的构造函数,而是将width_和height_保留为0,并且调用跟踪很奇怪。

联系方式:
https://github.com/speedyHKjournalist/OpenMapleClient/blob/main/app/src/main/cpp/src/IO/Window.cpp#L34
从跟踪看,似乎没有调用Error Game::init(android_app *pApp)?
跟踪:

  1. (lldb) thread backtrace
  2. * thread #1, name = 'ri0.glfwexample', stop reason = step over
  3. * frame #0: 0x0000007535ddfd70 libglfw-example.so`ms::Window::Window(this=0x00000075360ba990) at Window.cpp:34:21
  4. frame #1: 0x0000007535b5fad8 libglfw-example.so`::__cxx_global_var_init.10() at Singleton.h:33:17
  5. frame #2: 0x000000766d648bb8 linker64`__dl__ZN6soinfo17call_constructorsEv + 632
  6. frame #3: 0x000000766d63301c linker64`__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv + 2288
  7. frame #4: 0x000000766d62e100 linker64`__dl___loader_android_dlopen_ext + 88
  8. frame #5: 0x00000076561bc110 libdl.so`android_dlopen_ext + 24
  9. frame #6: 0x000000766b9243dc libnativeloader.so`android::NativeLoaderNamespace::Load(char const*) const + 200
  10. frame #7: 0x000000766b914e74 libnativeloader.so`OpenNativeLibraryInNamespace + 72
  11. frame #8: 0x000000766b91459c libnativeloader.so`OpenNativeLibrary + 140
  12. frame #9: 0x000000765191ae00 libandroid_runtime.so`android::loadNativeCode_native(_JNIEnv*, _jobject*, _jstring*, _jstring*, _jobject*, _jstring*, _jstring*, _jstring*, int, _jobject*, _jbyteArray*, _jobject*, _jstring*) + 308
  13. frame #10: 0x00000000721bec14 boot-framework.oat`art_jni_trampoline + 308
  14. frame #11: 0x00000075c0e18968 libart.so`art_quick_invoke_stub + 552
  15. frame #12: 0x00000075c0e85ff4 libart.so`art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*) + 196
  16. frame #13: 0x00000075c0fea3ec libart.so`art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*) + 408
  17. frame #14: 0x00000075c0fe618c libart.so`bool art::interpreter::DoCall<true, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 708
  18. frame #15: 0x00000075c0e2cd38 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 23432
  19. frame #16: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  20. frame #17: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  21. frame #18: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  22. frame #19: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  23. frame #20: 0x00000075c0fe6170 libart.so`bool art::interpreter::DoCall<true, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 680
  24. frame #21: 0x00000075c0e2dc40 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27280
  25. frame #22: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  26. frame #23: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  27. frame #24: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  28. frame #25: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  29. frame #26: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  30. frame #27: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  31. frame #28: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  32. frame #29: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  33. frame #30: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  34. frame #31: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  35. frame #32: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  36. frame #33: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  37. frame #34: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  38. frame #35: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  39. frame #36: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  40. frame #37: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  41. frame #38: 0x00000075c0fe5964 libart.so`bool art::interpreter::DoCall<false, true>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 1704
  42. frame #39: 0x00000075c0e54774 libart.so`void art::interpreter::ExecuteSwitchImplCpp<true, false>(art::interpreter::SwitchImplContext*) + 47036
  43. frame #40: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  44. frame #41: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  45. frame #42: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  46. frame #43: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  47. frame #44: 0x00000075c0fe5964 libart.so`bool art::interpreter::DoCall<false, true>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 1704
  48. frame #45: 0x00000075c0e52350 libart.so`void art::interpreter::ExecuteSwitchImplCpp<true, false>(art::interpreter::SwitchImplContext*) + 37784
  49. frame #46: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  50. frame #47: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  51. frame #48: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  52. frame #49: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  53. frame #50: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  54. frame #51: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  55. frame #52: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  56. frame #53: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  57. frame #54: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  58. frame #55: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  59. frame #56: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  60. frame #57: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  61. frame #58: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  62. frame #59: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  63. frame #60: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  64. frame #61: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  65. frame #62: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  66. frame #63: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  67. frame #64: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  68. frame #65: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  69. frame #66: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  70. frame #67: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  71. frame #68: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  72. frame #69: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  73. frame #70: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  74. frame #71: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  75. frame #72: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  76. frame #73: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  77. frame #74: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  78. frame #75: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  79. frame #76: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  80. frame #77: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  81. frame #78: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  82. frame #79: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  83. frame #80: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  84. frame #81: 0x00000075c0e2dc70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 27328
  85. frame #82: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  86. frame #83: 0x00000075c0fe4934 libart.so`art::interpreter::ExecuteSwitch(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool) + 324
  87. frame #84: 0x00000075c0fdccd4 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 224
  88. frame #85: 0x00000075c0fe44a8 libart.so`art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*) + 212
  89. frame #86: 0x00000075c0fe4f64 libart.so`bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) + 796
  90. frame #87: 0x00000075c0e2ce70 libart.so`void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*) + 23744
  91. frame #88: 0x00000075c0e24bdc libart.so`ExecuteSwitchImplAsm + 12
  92. frame #89: 0x00000075c136b554 libart.so`MterpInvokeStatic + 2552
  93. frame #90: 0x00000075c0e03998 libart.so`mterp_op_invoke_static + 24
  94. frame #91: 0x00000075c0fdcd30 libart.so`art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) + 316
  95. frame #92: 0x00000075c134e560 libart.so`artQuickToInterpreterBridge + 784
  96. frame #93: 0x00000075c0e2237c libart.so`art_quick_to_interpreter_bridge + 92
  97. frame #94: 0x00000075c0e22590 libart.so

字符串

gwbalxhn

gwbalxhn1#

正如@user17732522正确指出的那样,您无法保证初始化顺序。
因此,我将Singleton类更改为:

  1. template<class T>
  2. class Singleton {
  3. public:
  4. virtual ~Singleton() = default;
  5. static T &get() {
  6. static T instance_;
  7. return instance_;
  8. }
  9. private:
  10. T &operator=(const T &) = delete;
  11. };
  12. // No need for the code above
  13. // template<class T>
  14. // T Singleton<T>::instance_;

字符串

展开查看全部

相关问题