diff --git a/pgadmin/frm/events.cpp b/pgadmin/frm/events.cpp index 248e571..85bec80 100644 --- a/pgadmin/frm/events.cpp +++ b/pgadmin/frm/events.cpp @@ -44,6 +44,7 @@ static wxMutex s_BrowserTabMutex; static BrowserTabPtrList s_BrowserList; +static wxMutex s_CellChangeMutex; // Event table BEGIN_EVENT_TABLE(frmMain, pgFrame) @@ -457,8 +458,12 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode) // Get the item data, and feed it to the relevant handler, // cast as required. - currentObject = browser->GetObject(item); + // Locking the section, to prevent the race condition among, "onSelRightClick" and "execSelChange". + // + s_CellChangeMutex.Lock(); + currentObject = browser->GetObject(item); + s_CellChangeMutex.Unlock(); // If we didn't get an object, then we may have a right click, or // invalid click, so ignore. if (!currentObject) @@ -775,14 +780,18 @@ void frmMain::OnSelRightClick(wxTreeEvent &event) if (item != browser->GetSelection()) { browser->SelectItem(item); + // Preventing to change "currentObject" by "execSelchange" function by another thread. + // Will hold the lock, until we do popup on the respective object. + // + s_CellChangeMutex.Lock(); currentObject = browser->GetObject(item); } if (currentObject) doPopup(browser, event.GetPoint(), currentObject); + s_CellChangeMutex.Unlock(); } - void frmMain::OnDelete(wxCommandEvent &ev) { if (currentObject->CanDrop())