Usermode/AxWin4 - Fixing ID lookups of windows and clients
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / CClient.cpp
index 9fe806e..8640bf3 100644 (file)
@@ -12,7 +12,8 @@
 namespace AxWin {
 
 CClient::CClient(::AxWin::IIPCChannel& channel):
-       m_channel(channel)
+       m_channel(channel),
+       m_id(0)
 {
        
 }
@@ -24,21 +25,24 @@ CClient::~CClient()
 
 CWindow* CClient::GetWindow(int ID)
 {
-       if( ID == 0 )
-               return 0;
-       
-       return m_windows[ID];
+       try {
+               return m_windows.at(ID);
+       }
+       catch(const std::exception& e) {
+               return NULL;
+       }
 }
 
 void CClient::SetWindow(int ID, CWindow* window)
 {
        _SysDebug("SetWindow(ID=%i,window=%p)", ID, window);
-       if( m_windows[ID] ) {
-               delete m_windows[ID];
+       auto it = m_windows.find(ID);
+       if( it != m_windows.end() ) {
+               _SysDebug("CLIENT BUG: Window ID %i is already used by %p", ID, it->second);
+       }
+       else {
+               m_windows[ID] = window;
        }
-       _SysDebug("SetWindow - Set", ID, window);
-       m_windows[ID] = window;
-       _SysDebug("SetWindow - END");
 }
 
 void CClient::HandleMessage(CDeserialiser& message)

UCC git Repository :: git.ucc.asn.au