Patch #1539 2006-10-08 14:18

jthedering

Wrong XRCCTRL usage assert failure fixes
Download
1539-Wrong_XRCCTRL.patch (16.1 KB)
Category
Application::Bugfix
Status
Out of date
Close date
2007-04-12 12:44
Assigned to
 
Index: src/include/globals.h
===================================================================
--- src/include/globals.h    (Revision 3882)
+++ src/include/globals.h    (Arbeitskopie)
@@ -309,4 +309,15 @@
     extern DLLIMPORT windows_version_t WindowsVersion();
 };
 
+#ifdef __WXDEBUG__
+//This is equivalent to XRCCTRL, but doesn't cause an assert failure
+//if the control doesn't exist, so use it instead of XRCCTRL
+//if you check the existence yourself
+#define XRCCTRL_OR_NULL(window, id, type) \
+    (wxDynamicCast((window).FindWindow(XRCID(id)), type))
+#else
+#define XRCCTRL_OR_NULL(window, id, type) \
+    XRCCTRL(window, id, type)
+#endif // __WXDEBUG__
+
 #endif // SDK_GLOBALS_H
Index: src/plugins/compilergcc/compileroptionsdlg.cpp
===================================================================
--- src/plugins/compilergcc/compileroptionsdlg.cpp    (Revision 3882)
+++ src/plugins/compilergcc/compileroptionsdlg.cpp    (Arbeitskopie)
@@ -230,7 +230,7 @@
         XRCCTRL(*this, "lblBuildScriptsNote", wxStaticText)->Show(hasBuildScripts);
     }
 
-    wxChoice* cmb = XRCCTRL(*this, "cmbBuildMethod", wxChoice);
+    wxChoice* cmb = XRCCTRL_OR_NULL(*this, "cmbBuildMethod", wxChoice);
     if (cmb)
     {
         // build method is always "direct" now
@@ -441,7 +441,7 @@
 
 void CompilerOptionsDlg::DoFillVars()
 {
-    wxListBox* lst = XRCCTRL(*this, "lstVars", wxListBox);
+    wxListBox* lst = XRCCTRL_OR_NULL(*this, "lstVars", wxListBox);
     if (!lst)
         return;
     lst->Clear();
@@ -462,38 +462,38 @@
 
 void CompilerOptionsDlg::DoFillOthers()
 {
-    wxCheckBox* chk = XRCCTRL(*this, "chkIncludeFileCwd", wxCheckBox);
+    wxCheckBox* chk = XRCCTRL_OR_NULL(*this, "chkIncludeFileCwd", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/include_file_cwd"), false));
 
-    chk = XRCCTRL(*this, "chkIncludePrjCwd", wxCheckBox);
+    chk = XRCCTRL_OR_NULL(*this, "chkIncludePrjCwd", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/include_prj_cwd"), false));
 
-    chk = XRCCTRL(*this, "chkSaveHtmlLog", wxCheckBox);
+    chk = XRCCTRL_OR_NULL(*this, "chkSaveHtmlLog", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/save_html_build_log"), false));
 
-    chk = XRCCTRL(*this, "chkFullHtmlLog", wxCheckBox);
+    chk = XRCCTRL_OR_NULL(*this, "chkFullHtmlLog", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/save_html_build_log/full_command_line"), false));
 
-    chk = XRCCTRL(*this, "chkBuildProgressBar", wxCheckBox);
+    chk = XRCCTRL_OR_NULL(*this, "chkBuildProgressBar", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/build_progress/bar"), false));
 
-    chk = XRCCTRL(*this, "chkBuildProgressPerc", wxCheckBox);
+    chk = XRCCTRL_OR_NULL(*this, "chkBuildProgressPerc", wxCheckBox);
     if (chk)
         chk->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadBool(_T("/build_progress/percentage"), false));
 
-    wxSpinCtrl* spn = XRCCTRL(*this, "spnParallelProcesses", wxSpinCtrl);
+    wxSpinCtrl* spn = XRCCTRL_OR_NULL(*this, "spnParallelProcesses", wxSpinCtrl);
     if (spn)
     {
         spn->SetRange(1, 16);
         spn->SetValue(Manager::Get()->GetConfigManager(_T("compiler"))->ReadInt(_T("/parallel_processes"), 1));
     }
 
-    spn = XRCCTRL(*this, "spnMaxErrors", wxSpinCtrl);
+    spn = XRCCTRL_OR_NULL(*this, "spnMaxErrors", wxSpinCtrl);
     if (spn)
     {
         spn->SetRange(0, 1000);
@@ -737,7 +737,7 @@
         m_LinkerOptions = compiler->GetLinkerOptions();
         m_LinkLibs = compiler->GetLinkLibs();
 
-        wxChoice* cmb = XRCCTRL(*this, "cmbLogging", wxChoice);
+        wxChoice* cmb = XRCCTRL_OR_NULL(*this, "cmbLogging", wxChoice);
         if (cmb)
             cmb->SetSelection((int)compiler->GetSwitches().logging);
     }
@@ -797,7 +797,7 @@
     ArrayString2TextCtrl(m_LinkerOptions, XRCCTRL(*this, "txtLinkerOptions", wxTextCtrl));
 
     // only if "Commands" page exists
-    if (XRCCTRL(*this, "txtCmdBefore", wxTextCtrl))
+    if (XRCCTRL_OR_NULL(*this, "txtCmdBefore", wxTextCtrl))
     {
         ArrayString2TextCtrl(CommandsBeforeBuild, XRCCTRL(*this, "txtCmdBefore", wxTextCtrl));
         ArrayString2TextCtrl(CommandsAfterBuild, XRCCTRL(*this, "txtCmdAfter", wxTextCtrl));
@@ -885,7 +885,7 @@
         compiler->SetLinkerOptions(m_LinkerOptions);
         compiler->SetLinkLibs(m_LinkLibs);
 
-        wxChoice* cmb = XRCCTRL(*this, "cmbLogging", wxChoice);
+        wxChoice* cmb = XRCCTRL_OR_NULL(*this, "cmbLogging", wxChoice);
         if (cmb)
         {
             CompilerSwitches switches = compiler->GetSwitches();
@@ -899,7 +899,7 @@
         wxArrayString CommandsBeforeBuild;
         wxArrayString CommandsAfterBuild;
download for full patch...
jthedering 2006-10-08 14:23

XRCCTRL contains the contract that the referenced control should exist. When it is used to check if a control exists, like this

if(XRCCTRL(*this,"button",wxButton))

it will cause an assert failure in debug mode. Therefore I added a second form of XRCCTRL called XRCCTRL_MAYBE (please change the name if you wish) that can be used in those cases.

mandrav 2007-04-12 12:44

I know it is our fault (for taking so long to test and apply it), but this patch is now out of date (source code has changed since you submitted this patch).

If possible, please re-submit it for the current svn code and since you will do that, please submit separate patches for contrib plugins because they would have to be approved by their respective authors.

Thank you for your efforts.

jthedering 2007-04-23 23:35

Thank you for your interest.

This is a remade version of the patch for the latest svn code (revision 3882).