Author Topic: Crash when clean a single file  (Read 13719 times)

lfm

  • Guest
Crash when clean a single file
« on: May 24, 2006, 04:59:44 pm »
I'm using C::B 1.0 rev 2490.
When i open a .cpp single file (the file not inside project, no project), then click menu "Build->Clean", C::B crash.
I'm sorry, I using chinese WinXP-sp2. So, you maybe don't understand means of the error message picture.


[attachment deleted by admin]

Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
Re: Crash when clean a single file
« Reply #1 on: May 24, 2006, 05:23:16 pm »
lucky for us, the rpt file is better readable ;)
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Crash when clean a single file
« Reply #2 on: May 24, 2006, 11:02:08 pm »
The same thing happens if you try a rebuild with a single file (it's the same code).
The issue is in the method int CompilerGCC::Clean(ProjectBuildTarget* target) (for the clean case). At:
Code
    if (m_Project)
        wxSetWorkingDirectory(m_Project->GetBasePath());
    CompilerFactory::GetCompiler(m_CompilerId)->Init(m_Project);
The CompilerFactory::GetCompiler(m_CompilerId)->Init(m_Project); fails because m_CompilerId is "" (an empty string) which will cause GetCompiler(m_CompilerId) to return 0 (NULL)... It's the same for the rebuild command... I'm doing further research tomorrow becasue I'm far too tired for now...
With regards, Morten.
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Crash when clean a single file
« Reply #3 on: May 24, 2006, 11:09:09 pm »
...just a short addition before I go to bed: Maybe Compiler* CompilerFactory::GetCompiler(const wxString& id) should return the default compiler instead of 0 if it is passed an empty string? This would be more save... or not?!
With regards, Morten.
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 killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when clean a single file
« Reply #4 on: May 24, 2006, 11:13:11 pm »
in this case there's no compiler either from the
  - project
  - target
it seems we need to add an if test here, which should test for "no project/no target", it this test holds true it should either :
  - use CompilerFactory::GetDefaultCompiler()
  - or specify as compiler id :: CompilerFactory::GetDefaultCompilerID()

In case nobody has time to test this 'possible solution' I will try it out myself tomorrow.


(damn : CB crashed on me again, 'quick opening of workspace/project or whatsoever ... :-(  )


[EDIT] : Morton posted at the same time ;-) well the idea is not bad, but I think in this case it's good to stress that we explicitly want the default compiler, and it didn't gives us the default compiler because off a fallback protection safety net

PS : about the crash : again I have an empty rpt ....
« Last Edit: May 24, 2006, 11:17:55 pm by killerbot »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Crash when clean a single file
« Reply #5 on: May 24, 2006, 11:38:01 pm »
I'd like to propose a patch (see attached) for the clean and rebuild issue. This pretty much is what killerbot proposed, too (allthough I read his post just now, but we had the same idea, obviously). Anyway: There are a lot more glitches -> just search for "->Init(" in compilergcc.cpp. A lot of these initialisations could fail because CompilerFactory::GetCompiler(m_CompilerId) returns 0. I guess it's really worth a comment by mandrav. There should be a better solution as the patch -> maybe really what I've sated in my previous post never let CompilerFactory::GetCompiler(m_CompilerId) return 0 but the default compiler instead. How about that?
With regards, Morten.

Edit: This just came into my mind: CompilerFactory::GetDefaultCompilerID() and CompilerFactory::GetDefaultCompiler() could both return and empty string, too!!! This should be taken into account, so the "return default compiler instead" proposal may not be a good solution eigther...?!

[attachment deleted by admin]
« Last Edit: May 25, 2006, 08:21:16 am by MortenMacFly »
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

lfm

  • Guest
Re: Crash when clean a single file
« Reply #6 on: May 25, 2006, 01:54:29 am »
but if i open a project at 1st, then close this project. Now, open a single file, all is fine in this time .

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Crash when clean a single file
« Reply #7 on: May 25, 2006, 03:19:13 am »
MortenMacFly, maybe you should clean that patch up.  It is generally not a good idea to put the if and the statement it controls on the same line, it makes the code harder to read.  You should also lump the return -1 in with the same if() and not use 2.  Unless there is some reason for this?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Crash when clean a single file
« Reply #8 on: May 25, 2006, 08:28:25 am »
It is generally not a good idea to put the if and the statement it controls on the same line, it makes the code harder to read.
I generally agree. But in this very case I want to make clear that I'm using another call to CompilerFactory. This can visually be easy compared because it stands in the same alignment as within the line above.
In addition: A one-liner if statement can be written in one line. This is proposed by quite some standards (coding guidelines). So altogether this is kind of philosophic.

You should also lump the return -1 in with the same if() and not use 2.  Unless there is some reason for this?
Yes, there is a reason, of course -> the second if statement might not be issued if the first one already returns a valid compiler. But if this is not the case the second if statement is triggered. How would you do that? In the end if both fail we have to return without success. I guess don't understand.

BTW: What you did not see: I was missing the semicolon behind both first if-statements (in Clean and Rebuild).

With regards, Morten.
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Crash when clean a single file
« Reply #9 on: May 25, 2006, 08:30:00 am »
but if i open a project at 1st, then close this project. Now, open a single file, all is fine in this time .
I am aware of that. The reason is that m_CompilerId is a member variable that is properly set once you have opened a project. It is initialised by then so if you open a single file after a project the call to CompilerFactory::GetCompiler(m_CompilerId) will succeed.
With regards, Morten.
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 mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Crash when clean a single file
« Reply #10 on: May 25, 2006, 10:07:11 am »
Fixed in SVN, thanks.

For those interested, the bug was in CheckProject(). If no project was open, the last used compiler was used (i.e. it did nothing, just left things as they were). I changed it to use the default compiler in that case.
« Last Edit: May 25, 2006, 10:09:03 am by mandrav »
Be patient!
This bug will be fixed soon...

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Crash when clean a single file
« Reply #11 on: May 25, 2006, 10:13:42 am »
Edit: This just came into my mind: CompilerFactory::GetDefaultCompilerID() and CompilerFactory::GetDefaultCompiler() could both return and empty string, too!!! This should be taken into account, so the "return default compiler instead" proposal may not be a good solution eigther...?!

Actually, this isn't possible at all. C::B comes preconfigured with a handful of compilers and noone can delete them. This ensures that the above calls will always return correct values.
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when clean a single file
« Reply #12 on: May 25, 2006, 10:36:51 am »
the Don always comes up with the correct way to do it ;-)

but but but but, I can delete the internal compilers (without touching the source code) ......  :twisted: :twisted: :twisted:

[EDIT] : or at least some part of such a compiler

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Crash when clean a single file
« Reply #13 on: May 25, 2006, 10:44:28 am »
but but but but, I can delete the internal compilers (without touching the source code) ......  :twisted: :twisted: :twisted:

[EDIT] : or at least some part of such a compiler

Hmm, when I go to compiler options, the "Delete" button is disabled :)
If you 're talking about editing the .conf manually, then it wouldn't work still. It would auto-detect the missing compiler again on next startup ;). But then again, if you manually edit configuration files, you 're on your own  :twisted:
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Crash when clean a single file
« Reply #14 on: May 25, 2006, 10:51:11 am »
but but but but, I can delete the internal compilers (without touching the source code) ......  :twisted: :twisted: :twisted:

[EDIT] : or at least some part of such a compiler

Hmm, when I go to compiler options, the "Delete" button is disabled :)
If you 're talking about editing the .conf manually, then it wouldn't work still. It would auto-detect the missing compiler again on next startup ;). But then again, if you manually edit configuration files, you 're on your own  :twisted:
LOL