Jump to content

Recommended Posts

  • 3 weeks later...
  • Active Member
if (inv_item->GetType() == ITEM_BLEND && inv_item->GetVnum() == item->GetVnum())
{
	if (inv_item->GetCount() + item->GetCount() <= ITEM_MAX_COUNT && FN_compare_item_socket(inv_item, item))
    {
		inv_item->SetCount(inv_item->GetCount() + item->GetCount());
  		return inv_item;
	}
}

 

  • Love 1
  • Forum Moderator

For those who need FN_compare_item_socket function and also with fixed 'memory leak' which already is public.

  • Srcs/game/src/char_item.cpp

1.0) Add at the beginning of file:

static bool FN_compare_item_socket(const LPITEM pkItemSrc, const LPITEM pkItemDest)
{
	if (!pkItemSrc || !pkItemDest)
		return false;

	return memcmp(pkItemSrc->GetSockets(), pkItemDest->GetSockets(), sizeof(long) * ITEM_SOCKET_MAX_NUM) == 0;
}

2.0) Search for:

Spoiler


			if (inv_item->GetType() == ITEM_BLEND)
			{
				if (inv_item->GetVnum() == item->GetVnum())
				{
					if (inv_item->GetSocket(0) == item->GetSocket(0) &&
							inv_item->GetSocket(1) == item->GetSocket(1) &&
							inv_item->GetSocket(2) == item->GetSocket(2) &&
							inv_item->GetCount() < ITEM_MAX_COUNT)
					{
						inv_item->SetCount(inv_item->GetCount() + item->GetCount());
						return inv_item;
					}
				}
			}

 

 

2.1) Replace it with:

This is the hidden content, please

 

Edited by VegaS™
  • Metin2 Dev 49
  • Eyes 1
  • Confused 1
  • Scream 1
  • Lmao 1
  • Good 13
  • Love 2
  • Love 41
  • Active Member
15 hours ago, VegaS™ said:

For those who need FN_compare_item_socket function and also with fixed memory leak which already is public.

 

 

Where is the memory leak exactly ? There are just 2 LPITEM pointers entering in the function arguments, there is no "new" operator there ..

Maybe you were reffering to the memory leak of the blend item load function.

 

SF1p8h9.png

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Honorable Member
51 minutes ago, Exygo said:

 

Where is the memory leak exactly ? There are just 2 LPITEM pointers entering in the function arguments, there is no "new" operator there ..

Maybe you were reffering to the memory leak of the blend item load function.

 

 

He is talking about this topic

Actually there isn't a real memory leak there. Because CreateItem function is creating new CItem() and saving object to the m_VIDMap.

And look what is going on there

dfa58d2485.png

 

Edited by Metin2 Dev
Core X - External 2 Internal

 

3 hours ago, Mali61 said:

He is talking about this topic

Actually there isn't a real memory leak there. Because CreateItem function is creating new CItem() and saving object to the m_VIDMap.

And look what is going on there

dfa58d2485.png

 

Still, better to keep unused object deleted rather than keep them scrapping in memory.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Honorable Member
3 minutes ago, Sherer said:

Still, better to keep unused object deleted rather than keep them scrapping in memory.

That is why I said there isn't a real memory leak there

 

  • Active Member

by the way memcmp it's not for comparing item socket

3vELSlW.png

 

sadly ..

Edited by Metin2 Dev
Core X - External 2 Internal
  • Honorable Member
26 minutes ago, Exygo said:

by the way memcmp it's not for comparing item socket

3vELSlW.png

 

sadly ..

because memcmp usage is wrong, must be 0 if equals

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1

 

  • Forum Moderator
31 minutes ago, Exygo said:

by the way memcmp it's not for comparing item socket

https://en.cppreference.com/w/cpp/string/byte/memcmp

#define ITEM_SOCKET_MAX_NUM 3

int main()
{
	long lSockets[ITEM_SOCKET_MAX_NUM] = { 1, 2, 3 };
	long lSockets2[ITEM_SOCKET_MAX_NUM] = { 1, 2, 3 };
	cout << (memcmp(lSockets, lSockets2, sizeof(long) * ITEM_SOCKET_MAX_NUM) == 0) << endl;
	return 0;
}
//>> 1

 

Edited by VegaS™
  • Love 3
  • Honorable Member
3 minutes ago, Exygo said:

no, the problem is that memcmp must not be used to compare item socket ..

27ec1dfadc.png

db/Cache.cpp - OnFlush()

Edited by Metin2 Dev
Core X - External 2 Internal

 

  • Active Member

You don't need to post another example, I just gaved you one directly from the game.

21 hours ago, Mali61 said:

That is why I said there isn't a real memory leak there

Nowadays with so many system collectors (like built-in unix/windows) there isn't a real memory leak at all.

On the other hand if you keep stacking those unused items, memory will may grow to ridiculous values.

Same outcome you are going to have because of classic memory leak - a lot of memory is allocated most of them is junked.

  • Love 1
  • 6 months later...

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.