]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/treemodel.cpp
Prevent implicit Widget construction
[xonotic/netradiant.git] / radiant / treemodel.cpp
index 4d2f82384d8e62415ca44f9ac41644701bf063d6..d5a7a54a8b6a9dda4977210b55c6976f843c872e 100644 (file)
@@ -24,9 +24,8 @@
 #include "debugging/debugging.h"
 
 #include <map>
-#include <gtk/gtktreemodel.h>
-#include <gtk/gtktreednd.h>
-#include <gtk/gtkmain.h>
+#include <gtk/gtk.h>
+#include <uilib/uilib.h>
 
 #include "iscenegraph.h"
 #include "nameable.h"
@@ -280,7 +279,7 @@ static GtkTreePath* graph_tree_model_get_path( GtkTreeModel* tree_model, GtkTree
        graph_type& graph = *GRAPH_TREE_MODEL( tree_model )->graph;
        graph_type::iterator i = graph_iterator_read_tree_iter( iter );
 
-       GtkTreePath* path = gtk_tree_path_new();
+       GtkTreePath* path = ui::TreePath();
 
        for ( std::size_t depth = ( *i ).first.get().size(); depth != 0; --depth )
        {
@@ -647,7 +646,13 @@ void detach( const NameCallback& callback ){
 };
 
 void node_attach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       // Reference cannot be bound to dereferenced null pointer in well-defined
+       // C++ code, and Clang will assume that comparison below always evaluates
+       // to true, resulting in a segmentation fault.  Use a dirty hack to force
+       // Clang to check those "bad" references for null nonetheless.
+       volatile intptr_t n = (intptr_t)&node;
+
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->attach( callback );
@@ -655,7 +660,9 @@ void node_attach_name_changed_callback( scene::Node& node, const NameCallback& c
        }
 }
 void node_detach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->detach( callback );
@@ -874,7 +881,7 @@ static GtkTreePath* graph_tree_model_get_path( GtkTreeModel* tree_model, GtkTree
        ASSERT_MESSAGE( tree_model != 0, "RUNTIME ERROR" );
        GraphTreeNode* graph = GRAPH_TREE_MODEL( tree_model )->m_graph;
 
-       GtkTreePath* path = gtk_tree_path_new();
+       GtkTreePath* path = ui::TreePath(ui::New);
 
        for ( GraphTreeNode* node = ( *graph_iterator_read_tree_iter( iter ) ).second; node != graph; node = node->m_parent )
        {
@@ -1124,7 +1131,8 @@ void graph_tree_model_row_deleted( GraphTreeModel& model, GraphTreeNode::iterato
 const char* node_get_name( scene::Node& node );
 
 const char* node_get_name_safe( scene::Node& node ){
-       if ( &node == 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n == 0 ) {
                return "";
        }
        return node_get_name( node );
@@ -1142,7 +1150,8 @@ GraphTreeNode* graph_tree_model_find_parent( GraphTreeModel* model, const scene:
 }
 
 void node_attach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->attach( callback );
@@ -1150,7 +1159,8 @@ void node_attach_name_changed_callback( scene::Node& node, const NameCallback& c
        }
 }
 void node_detach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->detach( callback );
@@ -1358,7 +1368,7 @@ TestGraphTreeModel(){
 
        {
                GtkTreeIter iter;
-               GtkTreePath* path = gtk_tree_path_new_from_string( "0" );
+               GtkTreePath* path = ui::TreePath( "0" );
                gtk_tree_model_get_iter( model, &iter, path );
                gtk_tree_path_free( path );
 
@@ -1368,7 +1378,7 @@ TestGraphTreeModel(){
 
        {
                GtkTreeIter iter;
-               GtkTreePath* path = gtk_tree_path_new_from_string( "1" );
+               GtkTreePath* path = ui::TreePath( "1" );
                gtk_tree_model_get_iter( model, &iter, path );
                gtk_tree_path_free( path );