AurieFramework / YYToolkit

The definitive internal modding tool for GameMaker games
GNU Affero General Public License v3.0
72 stars 10 forks source link

Fatal Error: Exception 0xC0000005 occured at 00007FF943FE39D1 #52

Closed mashirochan closed 12 months ago

mashirochan commented 1 year ago

A fatal error has occured inside YYToolkit. Please report this occurence to the GitHub issue tracker.

Message: Exception 0xC0000005 occured at 00007FF943FE39D1

Version: YYToolkit 2.1.3b Early Injection: Disabled File: Src\MainEntry.cpp Line: 24 Debugger Present: No

Code that triggered crash:

else if (_strcmpi(Code->i_pName, "gml_Object_obj_Sticker_Collision_obj_Player") == 0) {
    auto Sticker_Collision_obj_Player = [](YYTKCodeEvent* pCodeEvent, CInstance* Self, CInstance* Other, CCode* Code, RValue* Res, int Flags) {
        PrintMessage(CLR_BRIGHTPURPLE, "Sticker Collision Detected!");
        YYRValue yyrv_collectedSticker;
        pCodeEvent->Call(Self, Other, Code, Res, Flags);
        CallBuiltin(yyrv_collectedSticker, "variable_global_get", Self, Other, { "collectedSticker" });
        auto obj_collectedSticker = static_cast<YYObjectBase*>(yyrv_collectedSticker);
        RValue result;
        const char* propertyName = "optionName";
        obj_collectedSticker->m_getOwnProperty(obj_collectedSticker, &result, propertyName);
        const char* optionName = static_cast<const char*>(result.Pointer);
        PrintMessage(CLR_BRIGHTPURPLE, "Sticker Name: %s", optionName);
    };
    Sticker_Collision_obj_Player(pCodeEvent, Self, Other, Code, Res, Flags);
    codeFuncTable[Code->i_CodeIndex] = Sticker_Collision_obj_Player;
}

After changing code, this still causes the same crash:

else if (_strcmpi(Code->i_pName, "gml_Object_obj_Sticker_Collision_obj_Player") == 0) {
    auto Sticker_Collision_obj_Player = [](YYTKCodeEvent* pCodeEvent, CInstance* Self, CInstance* Other, CCode* Code, RValue* Res, int Flags) {
        pCodeEvent->Call(Self, Other, Code, Res, Flags);
        YYRValue yyrv_collectedSticker;
        CallBuiltin(yyrv_collectedSticker, "variable_global_get", Self, Other, { "collectedSticker" });
        YYObjectBase* obj_collectedSticker = static_cast<YYObjectBase*>(yyrv_collectedSticker);
        for (int i = 0; i < obj_collectedSticker->m_yyvarsMap->m_curSize; i++) {
            if (obj_collectedSticker->m_yyvarsMap->m_pBuckets[i].Hash != 0 && obj_collectedSticker->m_yyvarsMap->m_pBuckets[i].v->Kind == VALUE_STRING) {
                PrintMessage(CLR_BRIGHTPURPLE, "%d Key: %d | Value: %s", i, obj_collectedSticker->m_yyvarsMap->m_pBuckets[i].k, obj_collectedSticker->m_yyvarsMap->m_pBuckets[i].v);
            }
        }
        /*RValue* optionName = nullptr;
        obj_collectedSticker->m_yyvarsMap->FindElement(stickerVarMap[0], optionName);*/
    };
    Sticker_Collision_obj_Player(pCodeEvent, Self, Other, Code, Res, Flags);
    codeFuncTable[Code->i_CodeIndex] = Sticker_Collision_obj_Player;
}

Game: HoloCure

Issue occurs when closing the sticker menu after picking up a sticker.

Archie-osu commented 1 year ago

Try stepping through the code and see where exactly you crash. Could be anything right now - a null pointer dereference, some invalid memory being accessed...

mashirochan commented 12 months ago

Is this an actual YYTK bug that needs reporting? Or will this only ever happen because of user error? Because if it's the latter, I've figured out how to do what I wanted, and the game no longer crashes. If this is an actual bug, then I can swap my code back and do some testing for you.

else if (_strcmpi(Code->i_pName, "gml_Object_obj_Sticker_Collision_obj_Player") == 0) {
    auto Sticker_Collision_obj_Player = [](YYTKCodeEvent* pCodeEvent, CInstance* Self, CInstance* Other, CCode* Code, RValue* Res, int Flags) {
        pCodeEvent->Call(Self, Other, Code, Res, Flags);
        YYRValue yyrv_collectedSticker;
        CallBuiltin(yyrv_collectedSticker, "variable_global_get", Self, Other, { "collectedSticker" });
        YYRValue yyrv_optionName;
        CallBuiltin(yyrv_optionName, "struct_get", Self, Other, { yyrv_collectedSticker, "optionName" });
        PrintMessage(CLR_BRIGHTPURPLE, "Sticker Name: %s", static_cast<const char*>(yyrv_optionName));
    };
    Sticker_Collision_obj_Player(pCodeEvent, Self, Other, Code, Res, Flags);
    codeFuncTable[Code->i_CodeIndex] = Sticker_Collision_obj_Player;
}
Archie-osu commented 12 months ago

Might have been user error, might have been struct misalignment. The lookup of variables via the hash map is not well tested, so it's recommended to just use GM builtins to do it.

mashirochan commented 12 months ago

I'd assuming it's just user error, because now I'm getting the same error message with just this small bit of simple code - I'm extremely C-lang illiterate, so I will just close this issue and chalk it up to my lack of knowledge in pointers, references, and callbacks.

for (int i = 0; i < yyrv_currentStickers.RefArray->length; i++) {
    CallBuiltin(yyrv_arrayValue, "array_get", Self, Other, { yyrv_currentStickers, (long long) i });
}