This is the worst code I've ever seen, even worse than Terraria and it's in an MMORPG called flyff.
Basically, when compiling under x64 it fails to save the game due to an invalid pointer.
How does this happen?
Sending the value to the other thread:
PostQueuedCompletionStatus(g_DbManager.m_hIOCPUpdate, (DWORD)pMover2, (DWORD)0, NULL);
Using the value on the other thread:
pMover = (CMover*)dwBytesTransferred;
Do you see the problem here? NO??
Let's check the documentation...
BOOL WINAPI PostQueuedCompletionStatus(
_In_ HANDLE CompletionPort,
_In_ DWORD dwNumberOfBytesTransferred,
_In_ ULONG_PTR dwCompletionKey,
_In_opt_ LPOVERLAPPED lpOverlapped
);
Now do you see the problem?
It's using the byte count parameter (dwNumberOfBytesTransferred
) for the value instead of the value parameter (dwCompletionKey
)
Here is the fixed code for x64:
Sending the value to the other thread:
PostQueuedCompletionStatus(g_DbManager.m_hIOCPUpdate, sizeof(pMover2), (ULONG_PTR)pMover2, NULL);
Using the value on the other thread:
pMover = (CMover*)dwCompletionKey;
How did this kind of code end up in an MMO out of anything?