[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43511] trunk/blender/source/blender: debug function DM_debug_info / DM_debug_print, with access from python

Nicholas Bishop nicholasbishop at gmail.com
Thu Jan 19 07:40:25 CET 2012


It was reported on IRC that this fails to build in release mode with scons.

I was able to get it building with a small addition to the SConscript,
but not sure if this fix is correct or not. I leave to someone else to
commit if so :)

Patch:
Index: source/blender/makesrna/intern/SConscript
===================================================================
--- source/blender/makesrna/intern/SConscript        (revision 43517)
+++ source/blender/makesrna/intern/SConscript     (working copy)
@@ -101,6 +101,10 @@ if env['OURPLATFORM'] in ('win32-vc',
'win32-mingw', 'linuxcross', 'win64-vc'):
 if env['WITH_BF_INTERNATIONAL']:
     defs.append('WITH_INTERNATIONAL')

+if not env['BF_DEBUG']:
+    defs.append('NDEBUG')
+
+
 makesrna_tool.Append(CPPDEFINES=defs)

 makesrna_tool.Append (CPPPATH = Split(incs))

On Wed, Jan 18, 2012 at 7:18 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
> Revision: 43511
>          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43511
> Author:   campbellbarton
> Date:     2012-01-19 00:18:25 +0000 (Thu, 19 Jan 2012)
> Log Message:
> -----------
> debug function DM_debug_info / DM_debug_print, with access from python
> through Object.dm_info('SOURCE/DEFORM/FINAL')
>
> this is to help tracking down issues with modifiers where loosing data
> layers between modifiers can cause bugs, also to helo with comparing
> bmesh/trunk's modifier stack.
>
> Modified Paths:
> --------------
>    trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
>    trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
>    trunk/blender/source/blender/makesrna/intern/rna_object_api.c
>
> Modified: trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
> ===================================================================
> --- trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h   2012-01-18 22:42:57 UTC (rev 43510)
> +++ trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h   2012-01-19 00:18:25 UTC (rev 43511)
> @@ -584,5 +584,10 @@
>  /* Set object's bounding box based on DerivedMesh min/max data */
>  void DM_set_object_boundbox(struct Object *ob, DerivedMesh *dm);
>
> +/* debug only */
> +#ifndef NDEBUG
> +char *DM_debug_info(DerivedMesh *dm);
> +void DM_debug_print(DerivedMesh *dm);
>  #endif
>
> +#endif
>
> Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
> ===================================================================
> --- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c        2012-01-18 22:42:57 UTC (rev 43510)
> +++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c        2012-01-19 00:18:25 UTC (rev 43511)
> @@ -2313,3 +2313,78 @@
>  #endif /* WITH_GAMEENGINE */
>
>  /* --- NAVMESH (end) --- */
> +
> +
> +/* derivedmesh info printing function,
> + * to help track down differences DM output */
> +
> +#ifndef NDEBUG
> +#include "BLI_dynstr.h"
> +
> +static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getElemDataArray)(DerivedMesh *, int))
> +{
> +       int type;
> +
> +       for (type = 0; type < CD_NUMTYPES; type++) {
> +               /* note: doesnt account for multiple layers */
> +               void *pt = getElemDataArray(dm, type);
> +               if (pt) {
> +                       const char *name = CustomData_layertype_name(type);
> +                       const int size = CustomData_sizeof(type);
> +                       const char *structname;
> +                       int structnum;
> +                       CustomData_file_write_info(type, &structname, &structnum);
> +                       BLI_dynstr_appendf(dynstr,
> +                                          "        dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
> +                                                          name, structname, type, (void *)pt, size, (int)(MEM_allocN_len(pt) / size));
> +               }
> +       }
> +}
> +
> +char *DM_debug_info(DerivedMesh *dm)
> +{
> +       DynStr *dynstr= BLI_dynstr_new();
> +       char *ret;
> +       const char *tstr;
> +
> +       BLI_dynstr_appendf(dynstr, "{\n");
> +       BLI_dynstr_appendf(dynstr, "    'ptr': '%p',\n", (void *)dm);
> +       switch (dm->type) {
> +               case DM_TYPE_CDDM:     tstr = "DM_TYPE_CDDM";     break;
> +               case DM_TYPE_EDITMESH: tstr = "DM_TYPE_EDITMESH";  break;
> +               case DM_TYPE_CCGDM:    tstr = "DM_TYPE_CCGDM";     break;
> +               default:               tstr = "UNKNOWN";           break;
> +       }
> +       BLI_dynstr_appendf(dynstr, "    'type': '%s',\n", tstr);
> +       BLI_dynstr_appendf(dynstr, "    'numVertData': %d,\n", dm->numVertData);
> +       BLI_dynstr_appendf(dynstr, "    'numEdgeData': %d,\n", dm->numEdgeData);
> +       BLI_dynstr_appendf(dynstr, "    'numFaceData': %d,\n", dm->numFaceData);
> +       BLI_dynstr_appendf(dynstr, "    'deformedOnly': %d,\n", dm->deformedOnly);
> +
> +       BLI_dynstr_appendf(dynstr, "    'vertexLayers': (\n");
> +       dm_debug_info_layers(dynstr, dm, dm->getVertDataArray);
> +       BLI_dynstr_appendf(dynstr, "    ),\n");
> +
> +       BLI_dynstr_appendf(dynstr, "    'edgeLayers': (\n");
> +       dm_debug_info_layers(dynstr, dm, dm->getEdgeDataArray);
> +       BLI_dynstr_appendf(dynstr, "    ),\n");
> +
> +       BLI_dynstr_appendf(dynstr, "    'faceLayers': (\n");
> +       dm_debug_info_layers(dynstr, dm, dm->getFaceDataArray);
> +       BLI_dynstr_appendf(dynstr, "    ),\n");
> +
> +       BLI_dynstr_appendf(dynstr, "}\n");
> +
> +       ret = BLI_dynstr_get_cstring(dynstr);
> +       BLI_dynstr_free(dynstr);
> +       return ret;
> +}
> +
> +void DM_debug_print(DerivedMesh *dm)
> +{
> +       char *str = DM_debug_info(dm);
> +       printf(str);
> +       fflush(stdout);
> +}
> +
> +#endif /* NDEBUG */
>
> Modified: trunk/blender/source/blender/makesrna/intern/rna_object_api.c
> ===================================================================
> --- trunk/blender/source/blender/makesrna/intern/rna_object_api.c       2012-01-18 22:42:57 UTC (rev 43510)
> +++ trunk/blender/source/blender/makesrna/intern/rna_object_api.c       2012-01-19 00:18:25 UTC (rev 43511)
> @@ -63,6 +63,7 @@
>  #include "BKE_font.h"
>  #include "BKE_mball.h"
>  #include "BKE_modifier.h"
> +#include "BKE_cdderivedmesh.h"
>
>  #include "DNA_mesh_types.h"
>  #include "DNA_scene_types.h"
> @@ -470,6 +471,44 @@
>        return object_is_modified(scene, ob) & settings;
>  }
>
> +#ifndef NDEBUG
> +void rna_Object_dm_info(struct Object *ob, int type, char *result)
> +{
> +       DerivedMesh *dm = NULL;
> +       int dm_release = FALSE;
> +       char *ret = NULL;
> +
> +       result[0] = '\0';
> +
> +       switch(type) {
> +               case 0:
> +                       if (ob->type == OB_MESH) {
> +                               dm = CDDM_from_mesh(ob->data, ob);
> +                               ret = DM_debug_info(dm);
> +                               dm_release = TRUE;
> +                       }
> +                       break;
> +               case 1:
> +                       dm = ob->derivedDeform;
> +                       break;
> +               case 2:
> +                       dm = ob->derivedFinal;
> +                       break;
> +       }
> +
> +       if (dm) {
> +               ret = DM_debug_info(dm);
> +               if (dm_release) {
> +                       dm->release(dm);
> +               }
> +               if (ret) {
> +                       strcpy(result, ret);
> +                       MEM_freeN(ret);
> +               }
> +       }
> +}
> +#endif /* NDEBUG */
> +
>  #else
>
>  void RNA_api_object(StructRNA *srna)
> @@ -483,6 +522,15 @@
>                {0, NULL, 0, NULL, NULL}
>        };
>
> +#ifndef NDEBUG
> +       static EnumPropertyItem mesh_dm_info_items[] = {
> +               {0, "SOURCE", 0, "Source", "Source mesh"},
> +               {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
> +           {2, "FINAL", 0, "Final", "Objects final mesh"},
> +               {0, NULL, 0, NULL, NULL}
> +       };
> +#endif
> +
>        /* mesh */
>        func= RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
>        RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied");
> @@ -585,6 +633,20 @@
>        RNA_def_property_flag(parm, PROP_REQUIRED);
>        parm= RNA_def_boolean(func, "result", 0, "", "Object visibility");
>        RNA_def_function_return(func, parm);
> +
> +
> +#ifndef NDEBUG
> +       /* mesh */
> +       func= RNA_def_function(srna, "dm_info", "rna_Object_dm_info");
> +       RNA_def_function_ui_description(func, "Returns a string for derived mesh data");
> +
> +       parm= RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
> +       RNA_def_property_flag(parm, PROP_REQUIRED);
> +       /* weak!, no way to return dynamic string type */
> +       parm= RNA_def_string(func, "result", "result", 1024, "result", "");
> +       RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
> +       RNA_def_function_output(func, parm);
> +#endif /* NDEBUG */
>  }
>
>
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs


More information about the Bf-committers mailing list