LiteLDev / LeviLamina

A lightweight, modular and versatile mod loader for Minecraft Bedrock Edition, formerly known as LiteLoaderBDS
https://levimc.org/software/levilamina
GNU Lesser General Public License v3.0
1.14k stars 117 forks source link

[Bug]: CustomForm 崩溃 #1502

Closed KobeBryant114514 closed 8 months ago

KobeBryant114514 commented 8 months ago

Describe the bug

此Bug仅能在 LL 0.10.4 复现

向玩家发送一个 ll::form::CustomForm form; 如果玩家点击了提交按钮,服务器就会崩溃。

具体为,只要 ll::form::CustomFormResult 这一个 optional不为空,无论后面写什么代码或者说不写代码,服务器就会崩溃。

To Reproduce

LL 0.10.4环境下

    ll::form::CustomForm form;
    form.setTitle("CustomForm")
        .appendLabel("label")
        .appendInput("input1", "input")
        .appendToggle("toggle", "toggle")
        .appendSlider("slider", "slider", 0, 100, 1)
        .appendStepSlider("stepSlider", "stepSlider", {"a", "b", "c"})
        .appendDropdown("dropdown", "dropdown", {"a", "b", "c"})
        .sendTo(pl, [](Player&, ll::form::CustomFormResult const& data, std::optional<ModalFormCancelReason>) {
            if (!data) {
                logger.info("CustomForm callback canceled");
                return;
            }
            for (auto [name, result] : *data) {
                static auto logDebugResult = [&](const ll::form::CustomFormElementResult& var) {
                    if (std::holds_alternative<uint64_t>(var)) {
                        logger.info("CustomForm callback {} = {}", name, std::get<uint64_t>(var));
                    } else if (std::holds_alternative<double>(var)) {
                        logger.info("CustomForm callback {} = {}", name, std::get<double>(var));
                    } else if (std::holds_alternative<std::string>(var)) {
                        logger.info("CustomForm callback {} = {}", name, std::get<std::string>(var));
                    }
                };
                logDebugResult(result);
            }
        });

以上代码来自 LL 的 Test https://github.com/LiteLDev/LeviLamina/blob/main/src/ll/test/FormTest.cpp

创建一个Custom发送给玩家 如果玩家点击了 x 关闭表单,则一切正常。 如果玩家点击了提交按钮,则服务器崩溃。

所以说这 Test 测了个寂寞?

Expected behavior

如果玩家点击了提交按钮,服务器不会崩溃。

Screenshots

No response

Platform

Windows11

Version

0.10.4

Additional context

No response