Jump to content

Invalid return value of a simple getter - compilation misconfiguration?


Go to solution Solved by Kibli,

Recommended Posts

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 = 0

 

As 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.

Edited by Kibli
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

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.