Jump to content

Recommended Posts

Hello m2dev , i am working on my server and i solved a lot in it but with this problem i need some help .

I don't know how to make this crashcore or when it happens and i don't have any idea of what is wrong.

 

Here are the crashcore details:

https://metin2.download/picture/43H0LcvF2D8Tgl9LQ27fSukhSD0a0n0N/.png

 

clearitem function:

 

void CHARACTER::ClearItem()
{
	int		i;
	LPITEM	item;
	
	for (i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
	{
		if ((item = GetInventoryItem(i)))
		{
			item->SetSkipSave(true);
			ITEM_MANAGER::instance().FlushDelayedSave(item);

			item->RemoveFromCharacter();
			M2_DESTROY_ITEM(item);

			SyncQuickslot(QUICKSLOT_TYPE_ITEM, i, 255);
		}
	}
	for (i = 0; i < DRAGON_SOUL_INVENTORY_MAX_NUM; ++i)
	{
		if ((item = GetItem(TItemPos(DRAGON_SOUL_INVENTORY, i))))
		{
			item->SetSkipSave(true);
			ITEM_MANAGER::instance().FlushDelayedSave(item);

			item->RemoveFromCharacter();
			M2_DESTROY_ITEM(item);
		}
	}
}

 

and destroy function:

void ITEM_MANAGER::DestroyItem(LPITEM item)
{
	if (item->GetSectree())
		item->RemoveFromGround();

	if (item->GetOwner())
	{
		if (CHARACTER_MANAGER::instance().Find(item->GetOwner()->GetPlayerID()) != NULL)
		{
			sys_err("DestroyItem: GetOwner %s %s!!", item->GetName(), item->GetOwner()->GetName());
			item->RemoveFromCharacter();
		}
		else
		{
			sys_err ("WTH! Invalid item owner. owner pointer : %p", item->GetOwner());
		}
	}

	TR1_NS::unordered_set<LPITEM>::iterator it = m_set_pkItemForDelayedSave.find(item);

	if (it != m_set_pkItemForDelayedSave.end())
		m_set_pkItemForDelayedSave.erase(it);

	DWORD dwID = item->GetID();
	sys_log(2, "ITEM_DESTROY %s:%u", item->GetName(), dwID);

	if (!item->GetSkipSave() && dwID)
	{
		DWORD dwOwnerID = item->GetLastOwnerPID();

		db_clientdesc->DBPacketHeader(HEADER_GD_ITEM_DESTROY, 0, sizeof(DWORD) + sizeof(DWORD));
		db_clientdesc->Packet(&dwID, sizeof(DWORD));
		db_clientdesc->Packet(&dwOwnerID, sizeof(DWORD));
	}
	else
	{
		sys_log(2, "ITEM_DESTROY_SKIP %s:%u (skip=%d)", item->GetName(), dwID, item->GetSkipSave());
	}

	if (dwID)
		m_map_pkItemByID.erase(dwID);

	m_VIDMap.erase(item->GetVID());
	M2_DELETE(item);
}
 
any idea is welcome , thank you for your time.
Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

The crash occured after a disconnect as you can see in the bt, the Disconnect() method and the ~CHARACTER destructor are called, for what i can see there's no problem with ClearItems() and DestroyItem(), post your CHARACTER::Destroy() method maybe there are more clues on what happened. It might be a double deletion of something since you get undefined behaviour if you try to delete an object through a pointer more that once. But the pointers in func args seem ok they don't look like bogus pointers.

Or maybe @WeedHex is right and you got db incosistencies.

  • Love 1
Link to comment
Share on other sites

void CHARACTER::Destroy()
{
    CloseMyShop();

    if (m_pkRegen)
    {
        if (m_pkDungeon) {
            if (m_pkDungeon->IsValidRegen(m_pkRegen, regen_id_)) {
                --m_pkRegen->count;
            }
        } else {
            if (is_valid_regen(m_pkRegen))
                --m_pkRegen->count;
        }
        m_pkRegen = NULL;
    }

    if (m_pkDungeon)
    {
        SetDungeon(NULL);
    }

#ifdef __PET_SYSTEM__
    if (m_petSystem)
    {
        m_petSystem->Destroy();
        delete m_petSystem;

        m_petSystem = 0;
    }
#endif

#ifdef ENABLE_MOUNT_COSTUME_SYSTEM
    if (m_mountSystem)
    {
        m_mountSystem->Destroy();
        delete m_mountSystem;
        m_mountSystem = 0;
    }
    
    if(GetMountVnum())
    {
        RemoveAffect(AFFECT_MOUNT);
        RemoveAffect(AFFECT_MOUNT_BONUS);
    }
#endif

    HorseSummon(false);

    if (GetRider())
        GetRider()->ClearHorseInfo();

    if (GetDesc())
        GetDesc()->BindCharacter(NULL);

    if (m_pkExchange)
        m_pkExchange->Cancel();

    SetVictim(NULL);

    if (GetShop())
    {
        GetShop()->RemoveGuest(this);
        SetShop(NULL);
    }

    ClearStone();
    ClearSync();
    ClearTarget();

    if (NULL == m_pkMobData)
    {
        DragonSoul_CleanUp();
        ClearItem();
    }

    LPPARTY party = m_pkParty;
    if (party)
    {
        if (party->GetLeaderPID() == GetVID() && !IsPC())
        {
            M2_DELETE(party);
        }
        else
        {
            party->Unlink(this);

            if (!IsPC())
                party->Quit(GetVID());
        }

        SetParty(NULL);
    }

    if (m_pkMobInst)
    {
        M2_DELETE(m_pkMobInst);
        m_pkMobInst = NULL;
    }

    m_pkMobData = NULL;

    if (m_pkSafebox)
    {
        M2_DELETE(m_pkSafebox);
        m_pkSafebox = NULL;
    }

    if (m_pkMall)
    {
        M2_DELETE(m_pkMall);
        m_pkMall = NULL;
    }

    m_set_pkChrSpawnedBy.clear();
    StopMuyeongEvent();
    event_cancel(&m_pkWarpNPCEvent);
    event_cancel(&m_pkRecoveryEvent);
    event_cancel(&m_pkDeadEvent);
    event_cancel(&m_pkSaveEvent);
    event_cancel(&m_pkTimedEvent);
    event_cancel(&m_pkStunEvent);
    event_cancel(&m_pkFishingEvent);
    event_cancel(&m_pkPoisonEvent);
    event_cancel(&m_pkFireEvent);
    event_cancel(&m_pkPartyRequestEvent);
    event_cancel(&m_pkWarpEvent);
    event_cancel(&m_pkCheckSpeedHackEvent);
    event_cancel(&m_pkMiningEvent);

    for (itertype(m_mapMobSkillEvent) it = m_mapMobSkillEvent.begin(); it != m_mapMobSkillEvent.end(); ++it)
    {
        LPEVENT pkEvent = it->second;
        event_cancel(&pkEvent);
    }
    
    m_mapMobSkillEvent.clear();
    ClearAffect();

    for (TMapBuffOnAttrs::iterator it = m_map_buff_on_attrs.begin();  it != m_map_buff_on_attrs.end(); it++)
    {
        if (NULL != it->second)
        {
            M2_DELETE(it->second);
        }
    }
    m_map_buff_on_attrs.clear();

    event_cancel(&m_pkDestroyWhenIdleEvent);

    if (m_pSkillLevels)
    {
        M2_DELETE_ARRAY(m_pSkillLevels);
        m_pSkillLevels = NULL;
    }

    CEntity::Destroy();

    if (GetSectree())
        GetSectree()->RemoveEntity(this);
    
#ifdef ENABLE_SYNC_HACK_FIX
    sync_hack = 0;
    sync_count = 0;
    sync_time = 0;
#endif
}

 

Link to comment
Share on other sites

I can't see anything wrong neither in this function, so probably you should check your db item_proto entries as suggested (you can also have a sys_err("deleting %d", item->GetVnum()) at the beginning of your DestroyItem() function, after /ip or /ipurge command load your character, with your latest item_proto entries (most likely there's nothing wrong with vanilla items) and then disconnect, if you get a core again you can check which item caused it in your sys_err since it will be last line before crash).

Link to comment
Share on other sites

Quote

Find the dwID of the item in your database, maybe is still there.

 

-Error with inventory cells

-Error on the item_proto (wronge size etc.)

-Other...

run this query in player db and report the results:
SELECT * FROM player.item WHERE id = 10019575;

according to bt thats the ID of the item that crashes core when you try to remove it.

  • Love 1
Link to comment
Share on other sites

You can try and add the following to get more debug info on what item you actually have here.

Change:

sys_err ("WTH! Invalid item owner. owner pointer : %p", item->GetOwner());

 

to:

sys_err ("WTH! Invalid item owner. %d owner pointer : %p", item->GetVnum(), item->GetOwner());

 

This should print out the vnum that's causing problems. Additionally, if you wanna try to make it crash-safe you'd return the function after it raises such an error. Though that could cause undefined behavior, so be careful with that.

Actually a missing owner is not the problem here. I think your core crashes when it tries to access a wrong pointer to your item. In short: It tries to access invalid memory. Thus leading to the crash. Please look at char_item.cpp on line 550 and tell us what this line exactly is, so we can see what's getting called exactly that causes the crash.

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

I said the problem, do not discuss the problem in vain.

Problem: Your inventory or market or trade or almost any object is not in memory. The core crashes because it is not in memory.
You cannot use the object that is not in memory in your bag or anywhere.

First of all, the object must be in memory.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.