Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 加载数据从。ini崩溃我的游戏!我能做什么?c++;_C++_File_Crash_Load_Ini - Fatal编程技术网

C++ 加载数据从。ini崩溃我的游戏!我能做什么?c++;

C++ 加载数据从。ini崩溃我的游戏!我能做什么?c++;,c++,file,crash,load,ini,C++,File,Crash,Load,Ini,你好,我正在尝试创建一个脚本来保存/加载我的游戏自定义武器布局。 保存功能工作正常,但如果我想加载布局,它会使我的游戏崩溃。 我知道问题在哪里,但我知道如何解决这些问题,所以我需要你的知识 void SaveWeaponsLayout() { Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini"); Log::Msg("Reading Data for WeaponsLayout.ini!"); Player pl

你好,我正在尝试创建一个脚本来保存/加载我的游戏自定义武器布局。 保存功能工作正常,但如果我想加载布局,它会使我的游戏崩溃。 我知道问题在哪里,但我知道如何解决这些问题,所以我需要你的知识

void SaveWeaponsLayout()
{
    Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini");
    Log::Msg("Reading Data for WeaponsLayout.ini!");
    Player playerPed = PLAYER::PLAYER_PED_ID();
    if (!ENTITY::IS_ENTITY_DEAD(playerPed))
    {
        for (auto & wpID : weaponLayoutList)
        {
            Hash weapon = wpID.weaponHash;
            char * wpName = wpID.WeaponName;
            if (WEAPON::HAS_PED_GOT_WEAPON(playerPed, wpID.weaponHash, 0))
            {
                int weaponInHex = weapon;
                std::string weaponInHex_ = hexify< int >(weaponInHex);
                wpLayout.WriteString(weaponInHex_, wpName, "WEAPONHASH");
            }
            for (auto & wpCompID : weaponComponentList)
            {
                Hash weaponComp = wpCompID.weaponCompHash;
                char * wpCompName = wpCompID.weaponComponent;
                if (WEAPON::HAS_PED_GOT_WEAPON_COMPONENT(playerPed, wpID.weaponHash, wpCompID.weaponCompHash))
                {
                    int weaponCompInHex = weaponComp;
                    std::string weaponCompInHex_ = hexify< int >(weaponCompInHex);
                    wpLayout.WriteString(weaponCompInHex_, wpName, wpCompName);
                }
            }
        }
    }
    Log::Msg("Files WeaponsLayout.ini created!");
    Notifications::MessageCentre6000("~p~Saved~s~: Weapons Layout");
}
…现在我的脚本给我带来了什么问题,因为它在我的文件中搜索所有武器和武器组件

void LoadWeaponsLayout()
{
    Log::Msg("Files reading WeaponsLayout.ini!");
    Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini");
    Player playerPed = PLAYER::PLAYER_PED_ID();
    if (!ENTITY::IS_ENTITY_DEAD(playerPed))
    {
        for (auto wpID : weaponLayoutList)
        {
            char * wpName = wpID.WeaponName;
            unsigned weaponX = wpLayout.GetInt(wpName, "WEAPONHASH");
            if (!WEAPON::HAS_PED_GOT_WEAPON(playerPed, weaponX, 0))
            {
                WEAPON::GIVE_DELAYED_WEAPON_TO_PED(playerPed, weaponX, 9999, 0);
                for (auto wpCompID : weaponComponentList)
                {
                    char * wpCompoName = wpCompID.weaponComponent;
                    unsigned weaponComp = wpLayout.GetInt(wpName, wpCompoName);
                    WAIT(0);
                    if (WEAPON::DOES_WEAPON_TAKE_WEAPON_COMPONENT(weaponX, weaponComp))
                    {
                        WEAPON::GIVE_WEAPON_COMPONENT_TO_PED(playerPed, weaponX, weaponComp);
                    }
                }
            }
        }
    }
    Log::Msg("Files WeaponsLayout.ini loaded!");
    Notifications::MessageCentre4000("~p~Loaded~s~: Weapons Layout");
}   
[我的ini类]

class Ini
{
private:
    std::string inifile;
public:

    Ini(std::string file)
    {
        this->inifile = file;
    }

    void WriteString(std::string string, std::string app, std::string key)
    {
        WritePrivateProfileStringA(app.c_str(), key.c_str(), string.c_str(), this->inifile.c_str());
    }

    std::string GetString(std::string app, std::string key)
    {
        char buf[100];
        GetPrivateProfileStringA(app.c_str(), key.c_str(), "NULL", buf, 100, this->inifile.c_str());
        return (std::string)buf;
    }

    void WriteInt(int value, std::string app, std::string key)
    {
        WriteString(std::to_string(value), app, key);
    }

    int GetInt(std::string app, std::string key)
    {
        return std::stoi(GetString(app, key));
    }
}
调试:

Files reading WeaponsLayout.ini!
Exception thrown at 0x000007FEFD71A06D in GTA5.exe: Microsoft C++ exception: std::invalid_argument at memory location 0x000000013AD4E610.
The thread 0x4628 has exited with code 0 (0x0).
The thread 0x4d78 has exited with code 0 (0x0).
The thread 0x4cd0 has exited with code 0 (0x0).
The thread 0x3c20 has exited with code 0 (0x0).
The thread 0x3678 has exited with code 0 (0x0).
The thread 0x1278 has exited with code 0 (0x0).
The thread 0x59a0 has exited with code 0 (0x0).
The thread 0x5458 has exited with code 0 (0x0).
The thread 0x4a8c has exited with code 0 (0x0).
The thread 0x5300 has exited with code 0 (0x0).
The thread 0x4b20 has exited with code 0 (0x0).
The thread 0x526c has exited with code 0 (0x0).
The thread 0x500c has exited with code 0 (0x0).
The thread 0x4be0 has exited with code 0 (0x0).
The thread 0x266c has exited with code 0 (0x0).
The thread 0x59ec has exited with code 0 (0x0).
The thread 0x3020 has exited with code 0 (0x0).
The thread 0x581c has exited with code 0 (0x0).
The thread 0x5098 has exited with code 0 (0x0).
The thread 0xd98 has exited with code 0 (0x0).
The thread 0x5180 has exited with code 0 (0x0).
The thread 0x1cc8 has exited with code 0 (0x0).
The thread 0x4c84 has exited with code 0 (0x0).
The thread 0x112c has exited with code 0 (0x0).
The thread 0x2dc0 has exited with code 0 (0x0).
The thread 0x5910 has exited with code 0 (0x0).
The thread 0x59cc has exited with code 0 (0x0).
The thread 0x2eb4 has exited with code 0 (0x0).
The thread 0x5aec has exited with code 0 (0x0).
The thread 0x58cc has exited with code 0 (0x0).
The thread 0x5a94 has exited with code 0 (0x0).
The thread 0x481c has exited with code 0 (0x0).
The thread 0x5554 has exited with code 0 (0x0).
The thread 0x2358 has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The thread 0x5764 has exited with code 0 (0x0).
The thread 0x53cc has exited with code 0 (0x0).
The thread 0x4ba4 has exited with code 0 (0x0).
The thread 0x4008 has exited with code 0 (0x0).
The thread 0x566c has exited with code 0 (0x0).
The thread 0x415c has exited with code 0 (0x0).
The thread 0x4cc0 has exited with code 0 (0x0).
The thread 0x512c has exited with code 0 (0x0).
The thread 0x5614 has exited with code 0 (0x0).
The thread 0x5390 has exited with code 0 (0x0).
The thread 0x4d68 has exited with code 0 (0x0).
The thread 0x56e8 has exited with code 0 (0x0).
The thread 0x54e8 has exited with code 0 (0x0).
The thread 0x1bc0 has exited with code 0 (0x0).
The thread 0x55d0 has exited with code 0 (0x0).
The thread 0x4f1c has exited with code 0 (0x0).
The thread 0x4efc has exited with code 0 (0x0).
The thread 0x54b4 has exited with code 0 (0x0).
The thread 0x4144 has exited with code 0 (0x0).
The thread 0x614 has exited with code 0 (0x0).
The thread 0x5820 has exited with code 0 (0x0).
The thread 0x4878 has exited with code 0 (0x0).
The thread 0x4184 has exited with code 0 (0x0).
The thread 0x2064 has exited with code 0 (0x0).
The thread 0x568c has exited with code 0 (0x0).
The thread 0x30cc has exited with code 0 (0x0).
The thread 0x57d8 has exited with code 0 (0x0).
The thread 0x5658 has exited with code 0 (0x0).
The thread 0x4c94 has exited with code 0 (0x0).
The thread 0x5084 has exited with code 0 (0x0).
The thread 0x4ff4 has exited with code 0 (0x0).
The thread 0x5858 has exited with code 0 (0x0).
The thread 0x148c has exited with code 0 (0x0).
The thread 0x209c has exited with code 0 (0x0).
The thread 0x52bc has exited with code 0 (0x0).
The thread 0x5170 has exited with code 0 (0x0).
The thread 0x1388 has exited with code 0 (0x0).
The thread 0xc10 has exited with code 0 (0x0).
The thread 0x12c0 has exited with code 0 (0x0).
The thread 0xca8 has exited with code 0 (0x0).
The thread 0x2040 has exited with code 0 (0x0).
The thread 0x4d1c has exited with code 0 (0x0).
The thread 0x358c has exited with code 0 (0x0).
The thread 0x1eac has exited with code 0 (0x0).
The thread 0x5608 has exited with code 0 (0x0).
The thread 0x28d8 has exited with code 0 (0x0).
The thread 0x4c44 has exited with code 0 (0x0).
The thread 0x5a0c has exited with code 0 (0x0).
The thread 0x4420 has exited with code 0 (0x0).
The thread 0x5828 has exited with code 0 (0x0).
The thread 0x29f4 has exited with code 0 (0x0).
The thread 0x4e60 has exited with code 0 (0x0).
The thread 0x54c4 has exited with code 0 (0x0).
The thread 0x4564 has exited with code 0 (0x0).
The thread 0x50ec has exited with code 0 (0x0).
The thread 0x43cc has exited with code 0 (0x0).
The thread 0x4e74 has exited with code 0 (0x0).
The thread 0x549c has exited with code 0 (0x0).
The thread 0xd74 has exited with code 0 (0x0).
The thread 0x5b90 has exited with code 0 (0x0).
The thread 0x4f7c has exited with code 0 (0x0).
The thread 0x30e8 has exited with code 0 (0x0).
The thread 0x4f74 has exited with code 0 (0x0).
The thread 0x1530 has exited with code 0 (0x0).
The thread 0x5584 has exited with code 0 (0x0).
DXGI WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live Producer at 0x0000000000474EA8, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x0000000000488880, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x00000000004640E0, Refcount: 1. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live                         Object :      2 [ STATE_CREATION WARNING #0: ]
The program '[22656] GTA5.exe' has exited with code 0 (0x0).

也许是时候学习如何使用调试器,以及如何在调试器中捕获崩溃,以确定崩溃发生在代码中的时间和地点。提出崩溃的任意原因不是调试,崩溃发生的确切位置以及导致崩溃的确切原因是什么?nullptr访问、gabage ptr访问、缓冲区溢出等…?在我看来,这是@Someprogrammerdude的建设性评论。调试不仅有助于我们准确地识别您的意思,而且有助于您自己解决问题。能够使用调试器是任何程序员的必备技能。人们不能简单地通过猜测和期望最好的结果来解决诸如崩溃之类的问题。要用肉眼分析崩溃,堆栈跟踪会有很大帮助。你可以从VS中复制/粘贴到你的问题中。。。
void LoadWeaponsLayout()
{
    Log::Msg("Files reading WeaponsLayout.ini!");
    Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini");
    Player playerPed = PLAYER::PLAYER_PED_ID();
    if (!ENTITY::IS_ENTITY_DEAD(playerPed))
    {
        for (auto wpID : weaponLayoutList)
        {
            char * wpName = wpID.WeaponName;
            unsigned weaponX = wpLayout.GetInt(wpName, "WEAPONHASH");
            if (!WEAPON::HAS_PED_GOT_WEAPON(playerPed, weaponX, 0))
            {
                WEAPON::GIVE_DELAYED_WEAPON_TO_PED(playerPed, weaponX, 9999, 0);
                for (auto wpCompID : weaponComponentList)
                {
                    char * wpCompoName = wpCompID.weaponComponent;
                    unsigned weaponComp = wpLayout.GetInt(wpName, wpCompoName);
                    WAIT(0);
                    if (WEAPON::DOES_WEAPON_TAKE_WEAPON_COMPONENT(weaponX, weaponComp))
                    {
                        WEAPON::GIVE_WEAPON_COMPONENT_TO_PED(playerPed, weaponX, weaponComp);
                    }
                }
            }
        }
    }
    Log::Msg("Files WeaponsLayout.ini loaded!");
    Notifications::MessageCentre4000("~p~Loaded~s~: Weapons Layout");
}   
class Ini
{
private:
    std::string inifile;
public:

    Ini(std::string file)
    {
        this->inifile = file;
    }

    void WriteString(std::string string, std::string app, std::string key)
    {
        WritePrivateProfileStringA(app.c_str(), key.c_str(), string.c_str(), this->inifile.c_str());
    }

    std::string GetString(std::string app, std::string key)
    {
        char buf[100];
        GetPrivateProfileStringA(app.c_str(), key.c_str(), "NULL", buf, 100, this->inifile.c_str());
        return (std::string)buf;
    }

    void WriteInt(int value, std::string app, std::string key)
    {
        WriteString(std::to_string(value), app, key);
    }

    int GetInt(std::string app, std::string key)
    {
        return std::stoi(GetString(app, key));
    }
}
Files reading WeaponsLayout.ini!
Exception thrown at 0x000007FEFD71A06D in GTA5.exe: Microsoft C++ exception: std::invalid_argument at memory location 0x000000013AD4E610.
The thread 0x4628 has exited with code 0 (0x0).
The thread 0x4d78 has exited with code 0 (0x0).
The thread 0x4cd0 has exited with code 0 (0x0).
The thread 0x3c20 has exited with code 0 (0x0).
The thread 0x3678 has exited with code 0 (0x0).
The thread 0x1278 has exited with code 0 (0x0).
The thread 0x59a0 has exited with code 0 (0x0).
The thread 0x5458 has exited with code 0 (0x0).
The thread 0x4a8c has exited with code 0 (0x0).
The thread 0x5300 has exited with code 0 (0x0).
The thread 0x4b20 has exited with code 0 (0x0).
The thread 0x526c has exited with code 0 (0x0).
The thread 0x500c has exited with code 0 (0x0).
The thread 0x4be0 has exited with code 0 (0x0).
The thread 0x266c has exited with code 0 (0x0).
The thread 0x59ec has exited with code 0 (0x0).
The thread 0x3020 has exited with code 0 (0x0).
The thread 0x581c has exited with code 0 (0x0).
The thread 0x5098 has exited with code 0 (0x0).
The thread 0xd98 has exited with code 0 (0x0).
The thread 0x5180 has exited with code 0 (0x0).
The thread 0x1cc8 has exited with code 0 (0x0).
The thread 0x4c84 has exited with code 0 (0x0).
The thread 0x112c has exited with code 0 (0x0).
The thread 0x2dc0 has exited with code 0 (0x0).
The thread 0x5910 has exited with code 0 (0x0).
The thread 0x59cc has exited with code 0 (0x0).
The thread 0x2eb4 has exited with code 0 (0x0).
The thread 0x5aec has exited with code 0 (0x0).
The thread 0x58cc has exited with code 0 (0x0).
The thread 0x5a94 has exited with code 0 (0x0).
The thread 0x481c has exited with code 0 (0x0).
The thread 0x5554 has exited with code 0 (0x0).
The thread 0x2358 has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The thread 0x5764 has exited with code 0 (0x0).
The thread 0x53cc has exited with code 0 (0x0).
The thread 0x4ba4 has exited with code 0 (0x0).
The thread 0x4008 has exited with code 0 (0x0).
The thread 0x566c has exited with code 0 (0x0).
The thread 0x415c has exited with code 0 (0x0).
The thread 0x4cc0 has exited with code 0 (0x0).
The thread 0x512c has exited with code 0 (0x0).
The thread 0x5614 has exited with code 0 (0x0).
The thread 0x5390 has exited with code 0 (0x0).
The thread 0x4d68 has exited with code 0 (0x0).
The thread 0x56e8 has exited with code 0 (0x0).
The thread 0x54e8 has exited with code 0 (0x0).
The thread 0x1bc0 has exited with code 0 (0x0).
The thread 0x55d0 has exited with code 0 (0x0).
The thread 0x4f1c has exited with code 0 (0x0).
The thread 0x4efc has exited with code 0 (0x0).
The thread 0x54b4 has exited with code 0 (0x0).
The thread 0x4144 has exited with code 0 (0x0).
The thread 0x614 has exited with code 0 (0x0).
The thread 0x5820 has exited with code 0 (0x0).
The thread 0x4878 has exited with code 0 (0x0).
The thread 0x4184 has exited with code 0 (0x0).
The thread 0x2064 has exited with code 0 (0x0).
The thread 0x568c has exited with code 0 (0x0).
The thread 0x30cc has exited with code 0 (0x0).
The thread 0x57d8 has exited with code 0 (0x0).
The thread 0x5658 has exited with code 0 (0x0).
The thread 0x4c94 has exited with code 0 (0x0).
The thread 0x5084 has exited with code 0 (0x0).
The thread 0x4ff4 has exited with code 0 (0x0).
The thread 0x5858 has exited with code 0 (0x0).
The thread 0x148c has exited with code 0 (0x0).
The thread 0x209c has exited with code 0 (0x0).
The thread 0x52bc has exited with code 0 (0x0).
The thread 0x5170 has exited with code 0 (0x0).
The thread 0x1388 has exited with code 0 (0x0).
The thread 0xc10 has exited with code 0 (0x0).
The thread 0x12c0 has exited with code 0 (0x0).
The thread 0xca8 has exited with code 0 (0x0).
The thread 0x2040 has exited with code 0 (0x0).
The thread 0x4d1c has exited with code 0 (0x0).
The thread 0x358c has exited with code 0 (0x0).
The thread 0x1eac has exited with code 0 (0x0).
The thread 0x5608 has exited with code 0 (0x0).
The thread 0x28d8 has exited with code 0 (0x0).
The thread 0x4c44 has exited with code 0 (0x0).
The thread 0x5a0c has exited with code 0 (0x0).
The thread 0x4420 has exited with code 0 (0x0).
The thread 0x5828 has exited with code 0 (0x0).
The thread 0x29f4 has exited with code 0 (0x0).
The thread 0x4e60 has exited with code 0 (0x0).
The thread 0x54c4 has exited with code 0 (0x0).
The thread 0x4564 has exited with code 0 (0x0).
The thread 0x50ec has exited with code 0 (0x0).
The thread 0x43cc has exited with code 0 (0x0).
The thread 0x4e74 has exited with code 0 (0x0).
The thread 0x549c has exited with code 0 (0x0).
The thread 0xd74 has exited with code 0 (0x0).
The thread 0x5b90 has exited with code 0 (0x0).
The thread 0x4f7c has exited with code 0 (0x0).
The thread 0x30e8 has exited with code 0 (0x0).
The thread 0x4f74 has exited with code 0 (0x0).
The thread 0x1530 has exited with code 0 (0x0).
The thread 0x5584 has exited with code 0 (0x0).
DXGI WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live Producer at 0x0000000000474EA8, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x0000000000488880, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x00000000004640E0, Refcount: 1. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live                         Object :      2 [ STATE_CREATION WARNING #0: ]
The program '[22656] GTA5.exe' has exited with code 0 (0x0).