rguplayer icon indicating copy to clipboard operation
rguplayer copied to clipboard

[Bug]项目编译失败,修补后编译的程序运行游戏时闪退

Open donmor opened this issue 1 year ago • 4 comments

我的编译环境为Arch Linux(已滚至最新)+GCC13/GCC14+Ruby 3.0.6,按照README编译时多次报错,在修补了部分文件后编译出可执行文件rgm,用来测试运行游戏(使用青鬼6.23汉化版)时,程序每次均卡死(使用killall -9结束)或闪退,日志中有[LOG] [Binding] Quit mri binding engine.,推测是Ruby部分出错。 使用GDB调试,在binding/mri/mri_util.h:150binding/mri/mri_main.cc:405处下断点,于150行处获取到每个载入Ruby的脚本,最终在载入102: Main时产生非0state,转至405行,循环中断。 已在x86_64和loongarch64(龙芯的自主架构)复现。 所做的改动:

$ git diff
diff --git a/app/rgu_main.cc b/app/rgu_main.cc
index 8e528b6..13ed552 100644
--- a/app/rgu_main.cc
+++ b/app/rgu_main.cc
@@ -148,10 +148,12 @@ int main(int argc, char* argv[]) {
 
 #if defined(OS_LINUX)
   auto* icon_ops =
-      SDL_RWFromConstMem(rgu_favicon_64_png, rgu_favicon_64_png_len);
+      SDL_IOFromConstMem(rgu_favicon_64_png, rgu_favicon_64_png_len);  // Renamed
+      //SDL_RWFromConstMem(rgu_favicon_64_png, rgu_favicon_64_png_len);
 
   if (icon_ops) {
-    auto* icon = IMG_Load_RW(icon_ops, SDL_TRUE);
+    //auto* icon = IMG_Load_RW(icon_ops, SDL_TRUE);
+    auto* icon = IMG_Load_IO(icon_ops, SDL_TRUE);  // Renamed
 
     if (icon) {
       SDL_SetWindowIcon(win->AsSDLWindow(), icon);
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt
index 231dc50..ee88637 100644
--- a/base/CMakeLists.txt
+++ b/base/CMakeLists.txt
@@ -66,5 +66,6 @@ endif()
 if (MSVC)
   target_compile_options(core_base PRIVATE /O2 /WX "$<$<CXX_COMPILER_ID:MSVC>:-utf-8>")
 else()
-  target_compile_options(core_base PRIVATE -O2 -Werror)
+	#target_compile_options(core_base PRIVATE -O2 -Werror)
+	#target_compile_options(core_base PRIVATE -O2)  # Removed -Werror
 endif()
diff --git a/base/buildflags/build.h b/base/buildflags/build.h
index 2b331c7..d4189fb 100644
--- a/base/buildflags/build.h
+++ b/base/buildflags/build.h
@@ -197,6 +197,11 @@
 #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__)
 #define ARCH_CPU_32_BITS 1
 #define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__loongarch64)  // Add loongarch
+#define ARCH_CPU_LOONGARCH_FAMILY 1
+#define ARCH_CPU_LOONGARCH64 1
+#define ARCH_CPU_64_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
 #elif defined(__MIPSEL__)
 #if defined(__LP64__)
 #define ARCH_CPU_MIPS_FAMILY 1
diff --git a/base/math/math.h b/base/math/math.h
index 58a3eed..80db061 100644
--- a/base/math/math.h
+++ b/base/math/math.h
@@ -332,7 +332,7 @@ class Rect {
     width = other.width;
     height = other.height;
     return other;
-  };
+  }  // Remove ';'
 
   bool operator==(const Rect& other) const {
     return other.x == x && other.y == y && other.width == width &&
@@ -453,4 +453,4 @@ class RectF {
 
 }  // namespace base
 
-#endif  // BASE_MATH_H_
\ No newline at end of file
+#endif  // BASE_MATH_H_
diff --git a/base/worker/run_loop.cc b/base/worker/run_loop.cc
index 6ab7469..764fa44 100644
--- a/base/worker/run_loop.cc
+++ b/base/worker/run_loop.cc
@@ -8,6 +8,7 @@
 #include <mutex>
 #include <queue>
 #include <thread>
+#include <condition_variable>  // Fix inclusions
 
 #include "base/third_party/concurrentqueue/blockingconcurrentqueue.h"
 
diff --git a/binding/mri/CMakeLists.txt b/binding/mri/CMakeLists.txt
index 81482fc..155013a 100644
--- a/binding/mri/CMakeLists.txt
+++ b/binding/mri/CMakeLists.txt
@@ -88,11 +88,18 @@ endif()
 
 add_library(binding_mri ${BINDING_MRI_SRC})
 target_link_libraries(binding_mri PUBLIC core_base core_renderer core_content core_ui mri_ruby zlibstatic)
-
+#target_link_libraries(binding_mri PUBLIC core_base core_renderer core_content core_ui mri_ruby zlibstatic -lruby)
+if (MSVC)  // From other modules
+  target_compile_options(binding_mri PRIVATE /O2 /WX "$<$<CXX_COMPILER_ID:MSVC>:-utf-8>")
+else()
+  #target_compile_options(binding_mri PRIVATE -O2 -Wno-incompatible-pointer-types)  // Suppress err
+  target_compile_options(binding_mri PRIVATE -Wno-incompatible-pointer-types)  // Remove -O2 for gdb debugging
+  endif()
 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
 if(EXISTS ${LIBFFI_DIR})
   target_compile_definitions(binding_mri PRIVATE HAS_LIBFFI_SUPPORT=1)
   target_link_libraries(binding_mri PRIVATE external-libffi)
   target_include_directories(binding_mri PRIVATE fiddle)
 endif()
-endif()
\ No newline at end of file
+endif()
diff --git a/binding/mri/mri_main.cc b/binding/mri/mri_main.cc
index 3ba8575..2ee0a7d 100644
--- a/binding/mri/mri_main.cc
+++ b/binding/mri/mri_main.cc
@@ -39,9 +39,9 @@
 #include "zlib.h"
 
 extern "C" {
-#if RAPI_FULL >= 300
-void rb_call_builtin_inits();
-#endif
+//#if RAPI_FULL >= 300
+//void rb_call_builtin_inits();
+//#endif  // In order to link the executable
 
 void Init_zlib(void);
 void Init_fiddle(void);
@@ -201,9 +201,9 @@ void BindingEngineMri::InitializeBinding(
 
   ruby_init_loadpath();
 
-#if RAPI_FULL >= 300
-  rb_call_builtin_inits();
-#endif
+//#if RAPI_FULL >= 300
+//  rb_call_builtin_inits();
+//#endif  // In order to link the executable
 
   rb_enc_set_default_internal(rb_enc_from_encoding(rb_utf8_encoding()));
   rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
diff --git a/content/CMakeLists.txt b/content/CMakeLists.txt
index 0faa405..26e0b42 100644
--- a/content/CMakeLists.txt
+++ b/content/CMakeLists.txt
@@ -85,5 +85,6 @@ target_link_libraries(core_content PUBLIC
 if (MSVC)
   target_compile_options(core_content PRIVATE /O2 /WX "$<$<CXX_COMPILER_ID:MSVC>:-utf-8>")
 else()
-  target_compile_options(core_content PRIVATE -O2 -Werror)
+	#target_compile_options(core_content PRIVATE -O2 -Werror)
+	#target_compile_options(core_content PRIVATE -O2)  // Remove -Werror
 endif()
diff --git a/renderer/CMakeLists.txt b/renderer/CMakeLists.txt
index 93f3f83..82b13d3 100644
--- a/renderer/CMakeLists.txt
+++ b/renderer/CMakeLists.txt
@@ -72,5 +72,6 @@ target_link_libraries(core_renderer PUBLIC core_base)
 if (MSVC)
   target_compile_options(core_renderer PRIVATE /O2 /WX "$<$<CXX_COMPILER_ID:MSVC>:-utf-8>")
 else()
-  target_compile_options(core_renderer PRIVATE -O2 -Werror)
+	#target_compile_options(core_renderer PRIVATE -O2 -Werror)
+	#target_compile_options(core_renderer PRIVATE -O2)  // Remove -Werror
 endif()
diff --git a/third_party/SDL b/third_party/SDL
--- a/third_party/SDL
+++ b/third_party/SDL
@@ -1 +1 @@
-Subproject commit a8ed32c5f74d282a902f5629a1398235ccec0789
+Subproject commit a8ed32c5f74d282a902f5629a1398235ccec0789-dirty
diff --git a/third_party/SDL_image b/third_party/SDL_image
--- a/third_party/SDL_image
+++ b/third_party/SDL_image
@@ -1 +1 @@
-Subproject commit affd69f7c37cd1b1e81838adf0d4f91c8c15e07b
+Subproject commit affd69f7c37cd1b1e81838adf0d4f91c8c15e07b-dirty
diff --git a/third_party/SDL_ttf b/third_party/SDL_ttf
--- a/third_party/SDL_ttf
+++ b/third_party/SDL_ttf
@@ -1 +1 @@
-Subproject commit 221ca5c837b59d0f2038701fb11e0b2690a6eef1
+Subproject commit 221ca5c837b59d0f2038701fb11e0b2690a6eef1-dirty
diff --git a/third_party/physfs b/third_party/physfs
--- a/third_party/physfs
+++ b/third_party/physfs
@@ -1 +1 @@
-Subproject commit 31209b7c2ce629dbda0db2329ce469ab9a2b90b9
+Subproject commit 31209b7c2ce629dbda0db2329ce469ab9a2b90b9-dirty
diff --git a/third_party/vorbis b/third_party/vorbis
--- a/third_party/vorbis
+++ b/third_party/vorbis
@@ -1 +1 @@
-Subproject commit 84c023699cdf023a32fa4ded32019f194afcdad0
+Subproject commit 84c023699cdf023a32fa4ded32019f194afcdad0-dirty
diff --git a/third_party/zlib b/third_party/zlib
--- a/third_party/zlib
+++ b/third_party/zlib
@@ -1 +1 @@
-Subproject commit 5c42a230b7b468dff011f444161c0145b5efae59
+Subproject commit 5c42a230b7b468dff011f444161c0145b5efae59-dirty

其中:

diff --git a/binding/mri/mri_main.cc b/binding/mri/mri_main.cc
index 3ba8575..2ee0a7d 100644
--- a/binding/mri/mri_main.cc
+++ b/binding/mri/mri_main.cc
@@ -39,9 +39,9 @@
 #include "zlib.h"
 
 extern "C" {
-#if RAPI_FULL >= 300
-void rb_call_builtin_inits();
-#endif
+//#if RAPI_FULL >= 300
+//void rb_call_builtin_inits();
+//#endif  // In order to link the executable
 
 void Init_zlib(void);
 void Init_fiddle(void);
@@ -201,9 +201,9 @@ void BindingEngineMri::InitializeBinding(
 
   ruby_init_loadpath();
 
-#if RAPI_FULL >= 300
-  rb_call_builtin_inits();
-#endif
+//#if RAPI_FULL >= 300
+//  rb_call_builtin_inits();
+//#endif  // In order to link the executable
 
   rb_enc_set_default_internal(rb_enc_from_encoding(rb_utf8_encoding()));
   rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

此处删除了rb_call_builtin_inits,因为此处一直链接失败(报undefined reference),经查证此函数位于ruby/array.c,推测此处是一个失效的hack。此处较大可能导致了闪退。 顺便问一下主程最后一次构建出可用的二进制时使用了什么环境,Ruby版本多少?

donmor avatar May 30 '24 12:05 donmor