On Thu, 7 Jun 2012 15:36:57 +0200
Antonio Ospite <[email protected]> wrote:

[...]
> I've got an experimental patch for BMElemSeq.sort() but I have a doubt,
> when I iterate on the bmesh elements after sorting them I don't get the
> elements in the order of their indices, look at the attached
> BMElemSeq_sort.log file.
> 
[...]
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 191fb61..8f591ed 100644
[...]
> +static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, 
> PyObject *kw)
> +{
> +     PyObject *keyfunc = NULL; /* optional */
> +     int reverse = FALSE; /* optional */
> +     static const char *kwlist[] = {"key", "reverse", NULL};
> +     int n_elem = 0;
> +
> +     BMIter iter;
> +     BMElem *ele;
> +     PyObject *py_elem = Py_None;
> +     PyObject *index = NULL;
> +
[...]
> +     i = 0;
> +     BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
> +             if (keyfunc != NULL) {
> +                     py_elem = BPy_BMElem_CreatePyObject(self->bm, (BMHeader 
> *)ele);
> +                     if (py_elem == Py_None) {
> +                             fprintf(stderr, "%s: failed to create a python 
> element!\n", __func__);
> +                             goto out;
> +                     }
> +                     index = PyObject_CallFunctionObjArgs(keyfunc, py_elem, 
> NULL);

If I add Py_DECREF(py_elem); here, the order is OK even immediately
after the sort, good!

I still haven't fully understood why tho.

Thanks,
   Antonio

-- 
Antonio Ospite
http://ao2.it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
_______________________________________________
Bf-python mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-python

Reply via email to