Kibli
-
Posts
2 -
Joined
-
Last visited
-
Feedback
0%
Content Type
Forums
Store
Third Party - Providers Directory
Feature Plan
Release Notes
Docs
Events
Posts posted by Kibli
-
-
Hello guys,
I updated the M2 Source on the serverside to C++17 for now and am using VS 2022 for compilation. Unfortunately, I have a very strange error which I was not able to solve until now and am asking for your opinions on the problem to get an idea about what's wrong.
The code (I added the log for debugging purposes as I was not sure if the VS debugging tools are working correctly):
void CHARACTER::SetPlayerProto(const TPlayerTable* t) { /* .... */ m_dwPlayerID = t->id; auto pmpid = &m_dwPlayerID; auto pid = GetPlayerID(); auto ppid = GetPlayerIDP(); LOG_INF("DEV !!! m_dwPlayerID = {}, t->id = {}, GetPlayerID() = {}", m_dwPlayerID, t->id, GetPlayerID()); LOG_INF("DEV !!! &m_dwPlayerID = {} ({} {}), GetPlayerIDP() = {} ({} {}), pid = {}", static_cast<const void*>(pmpid), *pmpid, m_dwPlayerID, static_cast<const void*>(ppid), *ppid, this->GetPlayerID(), pid); /* .... */ }
The getters in char.h:
public: uint32_t GetPlayerID() const { LOG_INF("DEV !!! RETURN {}", m_dwPlayerID); return m_dwPlayerID; } const uint32_t* GetPlayerIDP() const { return &m_dwPlayerID; }
The log output:
[2022-06-24 13:29:52.956] [info] [Log.cpp:12] DEV !!! m_dwPlayerID = 3, t->id = 3, GetPlayerID() = 0
[2022-06-24 13:29:52.956] [info] [Log.cpp:12] DEV !!! RETURN 0
[2022-06-24 13:29:52.956] [info] [Log.cpp:12] DEV !!! &m_dwPlayerID = 0x1401d9f8 (3 3), GetPlayerIDP() = 0x1401d9f8 (3 0), pid = 0As you can see, the "GetPlayerID()" function returns 0 for unknown reasons.
FYI: If I move the GetPlayerID function definition into the char.cpp, the return value is correct.
Do you have any idea what could cause this problem?
My guess is something in the compilation settings is not set correctly but they are very basic and look fine to me.
Invalid return value of a simple getter - compilation misconfiguration?
in Community Support - Questions & Answers
Posted
Problem fixed. A coding problem from an external system resulted in a memory layout issue.
Just remember: #pragma pack(0) - 0 is not a legal identifier
Either pop it or call #pragma pack() without 0
Regards