[glom/glom-1-20] CellRendererDbList: Do not crash if one of the fields is hidden.



commit 2162ae5adf3485f5a525b33d8475e66f694d34ed
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 29 21:00:18 2012 +0100

    CellRendererDbList: Do not crash if one of the fields is hidden.
    
    * glom/mode_data/datawidget/cellrenderer_dblist.cc:
    repack_cells_related(): Do not crash if create_cell() returns 0,
    and add a comment explaining that that is OK.
    * glom/mode_data/datawidget/cellcreation.cc: Add explanatory comments.
    
    This fixes the second crash mentioned in #668759 (alien).

 ChangeLog                                        |   11 +++++++++++
 glom/mode_data/datawidget/cellcreation.cc        |   10 ++++++++++
 glom/mode_data/datawidget/cellrenderer_dblist.cc |   16 +++++++++++++---
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d147020..86c8ef8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2012-01-29  Murray Cumming  <murrayc murrayc com>
 
+	CellRendererDbList: Do not crash if one of the fields is hidden.
+
+	* glom/mode_data/datawidget/cellrenderer_dblist.cc:
+	repack_cells_related(): Do not crash if create_cell() returns 0,
+	and add a comment explaining that that is OK.
+	* glom/mode_data/datawidget/cellcreation.cc: Add explanatory comments.
+
+	This fixes the second crash mentioned in #668759 (alien).
+
+2012-01-29  Murray Cumming  <murrayc murrayc com>
+
 	Choices: Allow the field to be be other than the primary key.
 
 	* glom/mode_data/datawidget/treemodel_db.h: Make most methods and
diff --git a/glom/mode_data/datawidget/cellcreation.cc b/glom/mode_data/datawidget/cellcreation.cc
index 5d8e8a2..b017ccf 100644
--- a/glom/mode_data/datawidget/cellcreation.cc
+++ b/glom/mode_data/datawidget/cellcreation.cc
@@ -30,6 +30,7 @@
 #include <libglom/utils.h>
 #include <libglom/db_utils.h>
 #include <libglom/data_structure/glomconversions.h>
+#include <iostream>
 
 
 namespace Glom
@@ -72,8 +73,14 @@ Gtk::CellRenderer* create_cell(const sharedptr<const LayoutItem>& layout_item, c
   sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(layout_item);
   if(item_field)
   {
+    //Ignore hiddent fields.
+    //For instance, these are generally added to DbTreeModels when they would not otherwise contain the primary key,
+    //so that the record can still be uniquely identified.
     if(item_field->get_hidden())
+    {
+      //std::cerr << G_STRFUNC << ": Returning 0 because the layout field is hidden. table_name=" << table_name << ", field name=" << item_field->get_name() << std::endl;
       return 0;
+    }
 
     switch(item_field->get_glom_type())
     {
@@ -160,7 +167,10 @@ Gtk::CellRenderer* create_cell(const sharedptr<const LayoutItem>& layout_item, c
   }
 
   if(!cell)
+  {
+    std::cerr << G_STRFUNC << ": Returning 0 because no cell was created." << std::endl;
     return 0;
+  }
 
   //Use formatting:
   sharedptr<const LayoutItem_WithFormatting> item_withformatting =
diff --git a/glom/mode_data/datawidget/cellrenderer_dblist.cc b/glom/mode_data/datawidget/cellrenderer_dblist.cc
index b60a932..89bac77 100644
--- a/glom/mode_data/datawidget/cellrenderer_dblist.cc
+++ b/glom/mode_data/datawidget/cellrenderer_dblist.cc
@@ -171,7 +171,10 @@ void CellRendererDbList::repack_cells_related(Gtk::CellLayout* combobox)
       //Get the default column, created by set_text_column():
       cell = combobox->get_first_cell();
       if(!cell)
-        std::cerr << G_STRFUNC << ": get_first_cell() returned null." << std::endl;
+      {
+        //This is normal, for instance if the item is meant to be hidden.
+        //std::cerr << G_STRFUNC << ": get_first_cell() returned null." << std::endl;
+      }
       else
       {
         //Unpack and repack it with expand=false instead of expand=true:
@@ -189,9 +192,16 @@ void CellRendererDbList::repack_cells_related(Gtk::CellLayout* combobox)
     {
       //Create the cell:
       cell = create_cell(layout_item, m_table_name, m_document, get_fixed_cell_height(*widget));
-      combobox->pack_start(*cell, true);
+      if(!cell)
+      {
+        std::cerr << G_STRFUNC << ": create_cell() return 0." << std::endl;
+      }
+      else
+      {
+        combobox->pack_start(*cell, true);
 
-      cell_connect_cell_data_func(combobox, cell, i);
+        cell_connect_cell_data_func(combobox, cell, i);
+      }
     }
 
     ++i;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]