Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown from SharedDtor() under VS2013 #346

Closed
richzw opened this issue May 5, 2015 · 1 comment
Closed

Exception thrown from SharedDtor() under VS2013 #346

richzw opened this issue May 5, 2015 · 1 comment

Comments

@richzw
Copy link

richzw commented May 5, 2015

Originally, The following codes can work well under VS2008. However, exception is thrown from SharedDtor() after upgrading to VS2013.

AGAMMQ_MESSAGE SerializeMsgMgr::CreateHostOnOffline()
{
    AGAMMQ_MESSAGE oMsg;
    memset(&oMsg,0,sizeof(AGAMMQ_MESSAGE));

    UIMessage uiMsg;
    uiMsg.set_version(toolset->Lic().GetVersion());

    UIMessage_Type msgType = uiMsg.msgtype();
    msgType = UIMessage_Type::UIMessage_Type_HOST_ON_OFF_LINE;
    uiMsg.set_msgtype(msgType);

    uiMsg.set_sequencenumber(0);
    uiMsg.set_bonusnumber(toolset->State().MyBonusUID().Bonus());

    HostOnOffline aHostOnOffline = uiMsg.hostonoffline();
    aHostOnOffline.set_ipaddress(std::string(ServerService::GetIPString()));
    aHostOnOffline.set_version(toolset->Lic().GetVersion());

    BonusType aType = aHostOnOffline.bonustype();
    aType = BonusType::LUCKY_COIN;
    aHostOnOffline.set_type(aType);

    HostType aHostType = aHostOnOffline.hosttype();
    aHostType = HostType::UNIFIED_SERVER;
    aHostOnOffline.set_hosttype(aBonusHostType);


    aHostOnOffline.set_time(GetCurrentTime());
    uiMsg.set_allocated_hostonoffline(&aHostOnOffline);
    int nBytes = uiMsg.ByteSize();
    if (nBytes <= 0)
    {
        return oMsg;
    }

    byte* pArray = new byte[nBytes];
    if (NULL == pArray)
    {
        return oMsg;
    }

    try{
        if (!uiMsg.SerializeToArray(pArray, nBytes))
        {
            delete [] pArray;
            return oMsg;
        }
    }
    catch(std::exception e)
    {

    }

    return oMsg;
}
@xfxyjwf
Copy link
Contributor

xfxyjwf commented May 5, 2015

The following line causes the problem:
uiMsg.set_allocated_hostonoffline(&aHostOnOffline);

Please refer to https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#fields for the behavior of set_allocated_foo.

@xfxyjwf xfxyjwf closed this as completed May 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants