I have an event class that looks like this:
class CEvent
{
void* m_pData;
EVENT_TYPE m_etEventType;
D3DXVECTOR2 m_vPos;
public:
void SetData(void* pData){ m_pData = pData; }
void SetEventType(EVENT_TYPE etEventType){ m_etEventType = etEventType; }
void SetPosition(D3DXVECTOR2 vPos){ m_vPos = vPos; }
void SetPosition(int x, int y) { m_vPos = D3DXVECTOR2((float)x,(float)y); }
int GetX(){ return (int)m_vPos.x; }
int GetY(){ return (int)m_vPos.y; }
void* GetData(){ return m_pData; }
};
Then I make a global instance of it named g_eMyEvent. Then I set the data using this:
g_eMyEvent.SetData("Message Event test.");
g_eMyEvent.SetEventType(MESSAGE);
g_eMyEvent.SetPosition(0,0);
And check if the player is at that position using this:
void UpdateLogic()
{
if(g_Engine.GetPlayerX() == g_eMyEvent.GetX() && g_Engine.GetPlayerY() == g_eMyEvent.GetY())
{
g_bUpdateMessageArea = TRUE;
strcpy(g_pMsgAreaTotal[g_iMsgAreaTotalIndex],(char*)g_eMyEvent.GetData());
g_iMsgAreaTotalIndex++;
}
if(g_bUpdateMessageArea == TRUE)
{
strcpy(g_pCurrentMsgArea,g_pMsgAreaTotal[g_iMsgAreaCurrentIndex]);
strcat(g_pCurrentMsgArea,"\n");
strcat(g_pCurrentMsgArea,g_pMsgAreaTotal[g_iMsgAreaCurrentIndex + 1]);
g_bUpdateMessageArea = FALSE;
}
}
It loads and displays it, but then closes and gives me an access violation. Does anybody know what I''m doing wrong? Thanks in advance.