Author Topic: Crash when opening workspace with non-existent projects  (Read 11007 times)

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Crash when opening workspace with non-existent projects
« on: January 29, 2006, 12:10:40 am »
Using Win XP x64 and revision 1889 SVN.

Opening a workspace that contains project which don't exist causes C::B to crash.

Steps to reproduce:

1. Open C::B and create new project, File -> New Project. I chose Console project named Console1. I saved it to Desktop\Console1\Console1.cbp.
2. Save the workspace, File -> Save workspace as... . I saved it to Desktop\wp.workspace.
3. Close C::B.
4. Delete the project directory, Desktop\Console1.
5. Double click the workspace file you created to open it in C::B.
6. C::B crashes.

The rpt file is attached.

[attachment deleted by admin]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #1 on: January 29, 2006, 10:44:51 am »
confirmed, I am already working on it.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #2 on: January 29, 2006, 11:28:00 am »
some first analysis (more to follow)

the offending line of code :
    m_pTree->Expand(m_pActiveProject->GetProjectNode());
in ProjectManager::LoadWorkSpace

Why : the workspace only had 1 project, which was the active on, the loading of that project failed (see REMARK 1)), so the m_pActiveProject is still NULL -->crash

REMARK 1 : Where does the loading fail, or where does the system know there's a problem with the project
ProjectManager::LoadWorkSpace -> m_pWorkspace = new cbWorkspace(filename)
This leads us to : WorkspaceLoader::Open() which tries to open all projects mentioned in the workspace.
Code
            wxFileName fname(projectFilename);
            fname.MakeAbsolute(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
            int active = 0;
            int ret = proj->QueryIntAttribute("active", &active);
            switch (ret)
            {
                case TIXML_SUCCESS:
                    if (active == 1)
                        GetpMan()->LoadProject(fname.GetFullPath(), true); // activate it
                    break;
                case TIXML_WRONG_TYPE:
                    GetpMsg()->DebugLog(_("Error %s: %s"), doc.Value(), doc.ErrorDesc());
                    GetpMsg()->DebugLog(_("Wrong attribute type (expected 'int')"));
                    break;
                default:
                    GetpMan()->LoadProject(fname.GetFullPath(), false); // don;t activate it
                    break;
In this case it's the TIXML_SUCCESS case with active == 1, and in the call to ProjectManager::LoadProject() it is discovered that the project can not be loaded, note the funtion will return NULL.

Since in the mentioned example, there are no other projects in the workspace, end of story and no m_pActiveProject.

Open Questions (for my further analysis) : what if there are more then 1 project in the workspace :
 - a non active fails to load
 - the active one fails to load, but others OK, m_pActiveProject still NULL ? if so make the next one active ??

It seems that in the example case, it is sure that there will never be an active project, --> offending line : if protect on m_pActiveProject != NULL.
Question : in such a case should we consider the workspace load to fail (since no project it contains was able to load) ?

.... to be continued

[EDIT 1] : just tested with 2 projects in workspace, with the 'active' one being failed, second one loads ok -> still no m_pActiveProject

[EDIT 2] : tested again with 2 projects in the workspace, but now the non-active going into failure, CodeBlocks error message box : Failed to create a temporary file name (error 267 : teh directory name is invalid), end result is the workspace is open with only the active project, second project : no sign of it.
« Last Edit: January 29, 2006, 01:03:42 pm by killerbot »

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Crash when opening workspace with non-existent projects
« Reply #3 on: January 29, 2006, 12:17:07 pm »
If I understood the code in the right way then cbProject::cbProject creates a new project if it can't load the given one. But: cbProject::m_Loaded is only set to true if cbProject::Save returns true. (Question: When does cbProject::Save return true and why does it return false in this case?)
After creating the cbProject instance (named project) for the deleted project-file ProjectManager::LoadProject checks if project->IsLoaded() returns true. This is obviously not the case because this should be the only situation (as long as the sanity-checks don't fail) in which ProjectManager::LoadProject could return 0. Then the project will obviously not activated (this would be the job of ProjectManager::LoadProject) and that way m_pActiveProject will be 0 if the active project fails to load.

The question now is: Is cbProject::Save (and all the functions that are called from there) supposed to return false in this case? I think If it returns true everything should go fine except that the active project is empty.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #4 on: January 29, 2006, 01:09:55 pm »
Correct analysis Der Meister. I also find that way of working a bit confusing. Probably save (did not check it yet) can have some arguments specifying construct if not existing or so ...

I have fixed the crash, will post my patch this evening (have to go play soccer now).

Example : 2 projects in workspace, active can not be loaded (since we removed it's directory or so), no crash, only second project loaded , that message box still shows up (will investigate that also this evening, since it's not so informative to thus user).
Result is : stil no 'active project', so you will need to activate manually the 'second' one and then you can compile it, etc ... (Build menu is mainly grayed out when no project is active).

More to come this evening ...

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Crash when opening workspace with non-existent projects
« Reply #5 on: January 29, 2006, 01:17:06 pm »
(have to go play soccer now).

 :D.

Michael

PS.: Good job anyway :).

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #6 on: January 29, 2006, 07:34:53 pm »
allrighty ...

Posting the patch at SF, this is what has changed :
 - no more crash
 - informs the user by means of message box that a specific project was unable to load
 - in case the failure project was the 'active' project, no active project, user will have to activate one him/her-self
 - modified files : projectmanager.cpp (actual fix) and workspaceloader.cpp (the 'good' feedback)


When the workspace is loaded (as far as I can see from the top level method call), then afterwards a new message box pops up saying that : "Failed to create a temporary file name (error : 267: the directory name is invalid)". Can't get rid of this one, I have no clue from which part of code it originates. :-(
But hey, the original problem is fixed, no crash, even some 'good' feedback, and then 'less good' feedback. ;-)


.............. posting at SF a little bit later, they are down and will be back shortly ....
[EDIT] : already attached here

[attachment deleted by admin]
« Last Edit: January 29, 2006, 07:38:39 pm by killerbot »

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Crash when opening workspace with non-existent projects
« Reply #7 on: January 29, 2006, 08:07:49 pm »
Glad to see this bug fixed, thanks killerbot!

BTW, if you ever drop by here in Finland, be sure to notify me first, I owe you a few beers. :) Oh, and don't forget to bring some warm clothes and a gun. People actually live in igloos here and we have had some polar bear problems lately...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #8 on: January 29, 2006, 08:21:56 pm »
I recently saw a polar bear too, on a deserted island in the pacific, I think, ... well on television that was, in the series "LOST"  8)
« Last Edit: January 29, 2006, 08:30:27 pm by killerbot »

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Crash when opening workspace with non-existent projects
« Reply #9 on: January 29, 2006, 08:52:01 pm »
Oh, and don't forget to bring some warm clothes and a gun. People actually live in igloos here and we have had some polar bear problems lately...

I would remeber your advice when I will go visit Finland... :D

Michael

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when opening workspace with non-existent projects
« Reply #10 on: January 29, 2006, 11:04:21 pm »
and patch is on SF