Author Topic: Possible crash during project close?  (Read 13943 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Possible crash during project close?
« on: December 02, 2012, 04:04:53 pm »
I'm trying to implement multple-select-project-close feature, but I've got a pretty strange crash in the CC.

Here is the patch:
Code
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp  (revision 8644)
+++ src/sdk/projectmanager.cpp  (working copy)
@@ -2325,23 +2325,37 @@ void ProjectManager::OnSaveProject(wxCommandEvent& WXUNUSED(event))

 void ProjectManager::OnCloseProject(wxCommandEvent& WXUNUSED(event))
 {
-    wxTreeItemId sel = GetTreeSelection();
-    if (!sel.IsOk())
+    if (m_IsLoadingProject)
+    {
+        wxBell();
         return;
+    }

-    FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
-    cbProject *proj = 0;
-    if (ftd)
-        proj = ftd->GetProject();
+    wxArrayTreeItemIds selections;
+    int count = m_pTree->GetSelections(selections);
+    if (count == 0)
+        return;
+    std::set<cbProject*> projectsToClose;

-    if (proj)
+    for (size_t ii = 0; ii < selections.GetCount(); ++ii)
     {
-        if (m_IsLoadingProject || proj->GetCurrentlyCompilingTarget())
-            wxBell();
-        else
-            CloseProject(proj);
+        FileTreeData *ftd = reinterpret_cast<FileTreeData*>(m_pTree->GetItemData(selections[ii]));
+        if (ftd->GetKind() != FileTreeData::ftdkProject)
+            continue;
+
+        cbProject *project = ftd->GetProject();
+        if (project)
+        {
+            if (project->GetCurrentlyCompilingTarget())
+                wxBell();
+            else
+                projectsToClose.insert(project);
+        }
     }

+    for (std::set<cbProject*>::iterator it = projectsToClose.begin(); it != projectsToClose.end(); ++it)
+        CloseProject(*it);
+
     if (m_pProjects->GetCount() > 0 && !m_pActiveProject)
         SetProject(m_pProjects->Item(0), false);

Index: src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 8644)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -2427,6 +2427,8 @@ void NativeParser::OnParserStart(wxCommandEvent& event)
     TRACE(_T("NativeParser::OnParserStart()"));

     cbProject* project = static_cast<cbProject*>(event.GetClientData());
+    if (!Manager::Get()->GetProjectManager()->IsProjectStillOpen(project))
+        project = nullptr;
     wxString   prj     = (project ? project->GetTitle() : _T("*NONE*"));
     const ParserCommon::ParserState state = static_cast<ParserCommon::ParserState>(event.GetInt());

The crash I've got was at this line "wxString   prj     = (project ? project->GetTitle() : _T("*NONE*"));"
I couldn't reproduce the crash unfortunately and I can't get you a backtrace.
Can someone of the CC gurus comment on this crash?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Possible crash during project close?
« Reply #1 on: December 03, 2012, 08:54:55 am »
Apply this patch, and try the CB workspace, and multi-select a lot of cbp, and context menu-> close project..... But no crash here. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible crash during project close?
« Reply #2 on: December 03, 2012, 09:34:35 am »
I suppose the timing is pretty important... :(
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible crash during project close?
« Reply #3 on: December 03, 2012, 12:47:57 pm »
But no crash here. :)
Same here: No crash. But I recall I had that seen line in the crash logs already... just a different use case. I just have no idea what could go wrong except that the pointer is not "nulled" correctly. But how (and actually where) would you do that if a project is deleted?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible crash during project close?
« Reply #4 on: December 03, 2012, 01:09:33 pm »
I suppose, I've got the crash by chance and now it won't happen for 1000 tries.

Is there some detection if a project is closed in CC? I see some timers, so if something like this happens:

1. detect if project is valid -> start CC for project on a timer
2. project is closed
3. timer starts executing

I'm sure it will be pretty nasty. I guess, the CC should be stopped and restarted if a project close is detected.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible crash during project close?
« Reply #5 on: December 03, 2012, 04:32:21 pm »
I've just got a similar crash.

Steps:
1. load a multi project workspace
2. start closing projects from bottom to top
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible crash during project close?
« Reply #6 on: December 03, 2012, 08:20:24 pm »
I guess, the CC should be stopped and restarted if a project close is detected.
It does that. cbEVT_PROJECT_CLOSE is connected with CodeCompletion::OnProjectClosed, where the project is removed from the/all parsers.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible crash during project close?
« Reply #7 on: December 09, 2012, 04:37:06 pm »
It does that. cbEVT_PROJECT_CLOSE is connected with CodeCompletion::OnProjectClosed, where the project is removed from the/all parsers.
I suppose something else is running on a timer or another thread that uses the same pointer after the project have been close.
My patch is in SVN, lets see if there are more crashes.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Martin K.

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Possible crash during project close?
« Reply #8 on: December 10, 2012, 07:53:45 am »
Hi,

I have seen that oBFusCATed is working on the project manager, maybe he is able to have a look on these points too:
1. when i have a project with more files as the project view can show on the screen and try to change some file options (right mouse click -> properties), than the project view scrolls to the bottom of the list after closing the property dialog.
2. when i change for e.g. advanced, use custom commands or the compile/link boxes, than the read only box on the first dialog page will be checked also.
3. sometimes, the lock symbol (for read only files) will not be shown in the list.

everything happens on windows, with 12.11 release.

Martin

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible crash during project close?
« Reply #9 on: December 10, 2012, 09:13:22 am »
I've seen some of these, but please do not hijack topics. If you want to discuss this please start a new one.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]