User forums > General (but related to Code::Blocks)

Codeblocks crash on linux when building single file

<< < (2/5) > >>

oBFusCATed:
Can you provide simple hello world project which demonstrates the problem?

Ghorgoth:
Sure,
here two hello world projects, one who crashes and the other who does not. (i just changed the targets order in the two projects).

Thanks,

oBFusCATed:
Thank you. I was able to reproduce the problem.
In fact there are two problems here:

1. The crash happens because of nullptr dereference.
This patch tries to fix it

--- Code: ---Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp     (revision 9573)
+++ src/plugins/compilergcc/compilergcc.cpp     (working copy)
@@ -2913,6 +2913,14 @@ int CompilerGCC::CompileFileWithoutProject(const wxString& file)
 int CompilerGCC::CompileFileDefault(cbProject* project, ProjectFile* pf, ProjectBuildTarget* bt)
 {
     Compiler* compiler = CompilerFactory::GetCompiler(bt->GetCompilerID());
+    if (!compiler)
+    {
+        const wxString &err = wxString::Format(_("error: Cannot build file for target '%s'. Compiler '%s' cannot be found!"),
+                                               bt->GetTitle().wx_str(), bt->GetCompilerID().wx_str());
+        LogMessage(pf->relativeToCommonTopLevelPath + _(": ") + err, cltError);
+        LogWarningOrError(cltError, project, pf->relativeToCommonTopLevelPath, wxEmptyString, err);
+        return -3;
+    }

     DirectCommands dc(this, compiler, project, m_PageIndex);
     wxArrayString compile = dc.CompileFile(bt, pf);

--- End code ---


2. The second problem is that the target points to the invalid windows target, but in the compiler toolbar I see that the linux target is selected.
    It seems that the CompilerGCC::GetBuildTargetForFile doesn't respect the non-supported target, so and it returns a windows only target on
    linux and vise-versa. The problem seems to go away with this patch:

--- Code: ---Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp     (revision 9573)
+++ src/plugins/compilergcc/compilergcc.cpp     (working copy)
@@ -2855,7 +2855,12 @@ ProjectBuildTarget* CompilerGCC::GetBuildTargetForFile(ProjectFile* pf)
         bt = m_pProject->GetBuildTarget(idx);
     }
     else // use the currently selected build target
-        bt = m_pProject->GetBuildTarget(m_RealTargetIndex); // pick the selected target
+    {
+        const wxString &targetName = m_Targets[m_TargetIndex];
+        if (std::find(pf->buildTargets.begin(), pf->buildTargets.end(), targetName) == pf->buildTargets.end())
+            return nullptr;
+        bt = m_pProject->GetBuildTarget(targetName);
+    }

     return bt;
 }

--- End code ---

@devs: Please comment, because I'm not too familiar with the Compiler's plugin, so I might be doing stupid things.

MortenMacFly:

--- Quote from: oBFusCATed on January 16, 2014, 01:17:11 am ---@devs: Please comment, because I'm not too familiar with the Compiler's plugin, so I might be doing stupid things.

--- End quote ---
What about the case when the user has specified a customs build command for a single file (via file properties). Is this still working after these changes?

oBFusCATed:
I'll need an example project and steps to help use this feature. I've never done this myself.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version