Jump to content

Recommended Posts

While reviewing the DestroyItem logic, I noticed a potential inconsistency in the ownership validation check.

Inside ITEM_MANAGER::DestroyItem(), the code performs the following lookup:

		if (CHARACTER_MANAGER::instance().Find(item->GetOwner()->GetPlayerID()) != nullptr)

However, Find() operates on the character VID map (m_map_pkChrByVID), while GetPlayerID() returns Player ID. This introduces a mismatch between the lookup key and the expected identifier type.

As a result, this check will almost always fail and return nullptr, meaning the condition is effectively not reliable for validating the character existence through this path.

From what I understand, this safety check was intended as a defensive check rather than part of the normal item lifecycle. In the standard execution flow, items owned by a character should already have been detached via RemoveFromCharacter() before reaching M2_DESTROY_ITEM, while items on the ground naturally have no owner and do not require this validation.

The concern arises in edge cases where the destruction flow is triggered while the item is still logically attached to a character. In such scenarios, this validation does not correctly reflect the real ownership state due to the PID/VID mismatch.

Fix Change Find() to FindByPID()

In item_manager.cpp, find:

if (CHARACTER_MANAGER::instance().Find(item->GetOwner()->GetPlayerID()) != nullptr)

Replace it with:

if (CHARACTER_MANAGER::instance().FindByPID(item->GetOwner()->GetPlayerID()) != nullptr)


special thanks to @ Abel(Tiger) and @ Gurgarath For taking the time to clarify this behavior.

  • Metin2 Dev 5
  • Love 4
Link to comment
https://metin2.dev/topic/34532-fix-on-destroyitem-safety-check/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.