EndstoneMC / endstone

Endstone - High-level Plugin API for Modding Bedrock Dedicated Servers (BDS), in both Python and C++.
http://endstone.dev/
Apache License 2.0
236 stars 22 forks source link

[bug]Crash getting player name when listening to events #66

Closed wuliao697 closed 4 days ago

wuliao697 commented 4 days ago

Describe the bug I'm trying to get the name of the player on the playerjoin event. Server crashes when players enter the game. I have no problem getting the player's uuid. This issue should have been a problem since version 0.5.1.

To Reproduce

class economyListener {
public:
    explicit economyListener(endstone::Plugin &plugin): plugin_(plugin){
    }

    void onPlayerJoin(endstone::PlayerJoinEvent &event)
    {
        const std::string playerName = event.getPlayer().getName();
        plugin_.getLogger().info(playerName);
    }

private:
    endstone::Plugin &plugin_;
};

Expected behavior

[2024-09-30 15:51:41.946 INFO] [EndstoneRuntime] Initialising...
[2024-09-30 15:51:42.396 INFO] [Server] setting up server logging...
[2024-09-30 15:51:42.397 INFO] [Server] Starting Server
[2024-09-30 15:51:42.397 INFO] [Server] Version: 1.21.30.03
[2024-09-30 15:51:42.397 INFO] [Server] Session ID: e11c36c6-d9ca-4282-ac01-2341773cb9c6
[2024-09-30 15:51:42.398 INFO] [Server] Build ID: 27468785
[2024-09-30 15:51:42.398 INFO] [Server] Branch: r/21_u3
[2024-09-30 15:51:42.398 INFO] [Server] Commit ID: b3c0841b46e46649a3a07a52d170008f6ce67ec4
[2024-09-30 15:51:42.398 INFO] [Server] Configuration: Publish
[2024-09-30 15:51:42.400 INFO] [Server] Level Name: Bedrock level
[2024-09-30 15:51:42.406 INFO] [Server] No CDN config file found for dedicated server
[2024-09-30 15:51:42.407 INFO] [Server] Game mode: 0 Survival
[2024-09-30 15:51:42.407 INFO] [Server] Difficulty: 1 EASY
[2024-09-30 15:51:42.407 INFO] [Server] Content logging to console is enabled.
[2024-09-30 15:51:43.529 INFO] [Server] This server is running Endstone version: 0.5.4.1 (Minecraft: 1.21.30)
[2024-09-30 15:51:44.277 INFO] [EconomyApi] Loading economy_api v0.1.0
[2024-09-30 15:51:44.278 INFO] [EconomyApi] EconomyAPI Loading!
[2024-09-30 15:51:44.278 INFO] [Database] Opening level 'worlds/Bedrock level/db'
[2024-09-30 15:51:44.315 INFO] [Server] [SERVER] Pack Stack - None
[2024-09-30 15:51:46.411 INFO] [Network] IPv4 supported, port: 19132: Used for gameplay and LAN discovery
[2024-09-30 15:51:46.412 INFO] [Network] IPv6 supported, port: 19133: Used for gameplay
[2024-09-30 15:51:46.437 INFO] [Server] Server started.
[2024-09-30 15:51:46.437 INFO] [Server] ================ TELEMETRY MESSAGE ===================
[2024-09-30 15:51:46.438 INFO] [Server] Server Telemetry is currently not enabled.
[2024-09-30 15:51:46.438 INFO] [Server] Enabling this telemetry helps us improve the game.
[2024-09-30 15:51:46.438 INFO] [Server] To enable this feature, add the line 'emit-server-telemetry=true'
[2024-09-30 15:51:46.438 INFO] [Server] to the server.properties file in the handheld/src-server directory
[2024-09-30 15:51:46.438 INFO] [Server] ======================================================
[2024-09-30 15:51:46.472 INFO] [EconomyApi] Enabling economy_api v0.1.0
[2024-09-30 15:51:46.472 INFO] [EconomyApi] EconomyAPI Activated
[2024-09-30 15:51:46.473 INFO] [Scripting] [Scripting] No script plugins found.
[2024-09-30 15:51:50.644 INFO] [Server] Player connected: wuliao697, xuid: 2535454729832610
[2024-09-30 15:51:57.926 INFO] [Server] Player Spawned: wuliao697 xuid: 2535454729832610, pfid: bf363b7739b8fc5f
=== ENDSTONE CRASHED! - PLEASE REPORT THIS AS AN ISSUE ON GITHUB ===
Operation system: Windows
Endstone version: 0.5.4.1
Api version     : 0.5
Description     : Exception unhandled: 0xc0000005
Stack trace (most recent call first):
#0  0x7fffbc62a30f     (0x1800ca30f) in endstone::detail::`anonymous namespace'::exception_filter(_EXCEPTION_POINTERS*) at D:\a\endstone\endstone\src\endstone_runtime\windows\signal_handler.cpp:53
#1  0x7ff86f6a0b0b     (0x180160b0b) in UnhandledExceptionFilter
#2  0x7ff871f9987c     (0x1800a987c) in RtlCopyMemory
#3  0x7ff871f7f6a6     (0x18008f6a6) in __C_specific_handler
#4  0x7ff871f951de     (0x1800a51de) in __chkstk
#5  0x7ff871f0e865     (0x18001e865) in RtlFindCharInUnicodeString
#6  0x7ff871f941cd     (0x1800a41cd) in KiUserExceptionDispatcher
#7  0x7ff836e5c733     (0x18001c733) in init_endstone_plugin
#8  0x7ff836e6a96b     (0x18002a96b) in init_endstone_plugin
#9  0x7ff836e4854a     (0x18000854a) in  ??
#10 0x7ff836e56698     (0x180016698) in  ??
#11 0x7fffbc6ca3b0     (0x18016a3b0) in endstone::detail::EndstonePluginManager::callEvent(endstone::detail::EndstonePluginManager*) at D:\a\endstone\endstone\src\endstone_core\plugin\plugin_manager.cpp:199
#12 0x7fffbc5aebd4     (0x18004ebd4) in ServerPlayer::setLocalPlayerAsInitialized() at D:\a\endstone\endstone\src\endstone_runtime\bedrock\server\server_player.cpp:92
#13 0x7ff796d746d1     (0x1407d46d1) in  ??
#14 0x7ff796d6b17a     (0x1407cb17a) in  ??
#15 0x7ff796d88b68     (0x1407e8b68) in  ??
#16 0x7ff797cf8eae     (0x141758eae) in  ??
#17 0x7ff7971c9b00     (0x140c29b00) in  ??
#18 0x7ff7971bf35e     (0x140c1f35e) in  ??
#19 0x7ff79713af6d     (0x140b9af6d) in  ??
#20 0x7ff86f449332     (0x180029332) in _recalloc
#21 0x7ff8718b257c     (0x18001257c) in BaseThreadInitThunk
#22 0x7ff871f4af27     (0x18005af27) in RtlUserThreadStart
wu-vincent commented 4 days ago

9 0x7ff836e4854a (0x18000854a) in ??

10 0x7ff836e56698 (0x180016698) in ??

These traces suggest the crash is from your plugin than endstone itself. Try to build your plugin with RelWithDebInfo and place the pdb file next to your plugin.

wuliao697 commented 4 days ago

I tried switching RelWithDebInfo, but I have another problem. It won't build after the change. So I tried to build the endstone example plugin. Already deleted the previous build file and had the same problem as this one. Before this I was able to build successfully.

"G:\CLion 2023.3.3\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\...\cpp-example-plugin-main\cmake-build-release --target cpp_example -j 6
[1/3] Linking CXX static library _deps\fmt-build\fmt.lib
[2/3] Building CXX object CMakeFiles\cpp_example.dir\src\example_plugin.cpp.obj
FAILED: CMakeFiles/cpp_example.dir/src/example_plugin.cpp.obj 
C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1438~1.331\bin\Hostx64\x64\cl.exe  /nologo /TP -Dcpp_example_EXPORTS -IC:\Users\admin\...\cpp-example-plugin-main\include -IC:\Users\admin\...\cpp-example-plugin-main\cmake-build-release\_deps\endstone-src\include -IC:\Users\admin\...\cpp-example-plugin-main\cmake-build-release\_deps\fmt-src\include /DWIN32 /D_WINDOWS /GR /EHsc /D_ITERATOR_DEBUG_LEVEL=0 /O2 /Ob2 /DNDEBUG -std:c++17 -MD /showIncludes /FoCMakeFiles\cpp_example.dir\src\example_plugin.cpp.obj /FdCMakeFiles\cpp_example.dir\ /FS -c C:\...\cpp-example-plugin-main\src\example_plugin.cpp
C:\...\cpp-example-plugin-main\cmake-build-release\_deps\endstone-src\include\endstone/util/result.h(17): fatal error C1083: 无法打开包括文件: “nonstd/expected.hpp”: No such file or directory
ninja: build stopped: subcommand failed.

I apologize for my cheap shot on these.

wu-vincent commented 4 days ago

It seems likely that the issue is related to the version specified in the CMakeLists.txt. Please try changing the GIT_TAG from main to the release version you are using (e.g., v0.5.4 or v0.5.4.1). If the version isn’t fixed, the build will pull the latest commit from upstream. This explains the crashes in your case due to ABI breaks, as we are frequently making changes to the C++ API.

wuliao697 commented 4 days ago

Problem solved, really appreciate it. I wish this community project will be better and better.