Constraints Bugfix:

IK-constraint "flush_targets" function was causing segfaults on debug builds from certain MSVC compilers. 

The cause of this, is that ct is freed in the SINGLETARGET_FLUSH_TARS macro already, but ct is accessed in the following line to get the next target (ct= ct->next). Caused by brecht's commit for the pole-target stuff for IK-constraint.

Now the SINGLETARGET_FLUSH_TARS macro, and the SINGLETARGETNS_FLUSH_TARS macro will correctly advance the location that ct points to.
This commit is contained in:
Joshua Leung
2007-12-06 10:20:03 +00:00
parent ac6efff0d7
commit 1e45289f91

View File

@@ -874,12 +874,14 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
/* This following macro should be used for all standard single-target *_flush_tars functions /* This following macro should be used for all standard single-target *_flush_tars functions
* to save typing and reduce maintainance woes. * to save typing and reduce maintainance woes.
* Note: the pointer to ct will be changed to point to the next in the list (as it gets removed)
* (Hopefully all compilers will be happy with the lines with just a space on them. Those are * (Hopefully all compilers will be happy with the lines with just a space on them. Those are
* really just to help this code easier to read) * really just to help this code easier to read)
*/ */
#define SINGLETARGET_FLUSH_TARS(con, datatar, datasubtarget, ct, list, nocopy) \ #define SINGLETARGET_FLUSH_TARS(con, datatar, datasubtarget, ct, list, nocopy) \
{ \ { \
if (ct) { \ if (ct) { \
bConstraintTarget *ctn = ct->next; \
if (nocopy == 0) { \ if (nocopy == 0) { \
datatar= ct->tar; \ datatar= ct->tar; \
strcpy(datasubtarget, ct->subtarget); \ strcpy(datasubtarget, ct->subtarget); \
@@ -887,23 +889,27 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
} \ } \
\ \
BLI_freelinkN(list, ct); \ BLI_freelinkN(list, ct); \
ct= ctn; \
} \ } \
} }
/* This following macro should be used for all standard single-target *_flush_tars functions /* This following macro should be used for all standard single-target *_flush_tars functions
* to save typing and reduce maintainance woes. It does not do the subtarget related operations * to save typing and reduce maintainance woes. It does not do the subtarget related operations.
* Note: the pointer to ct will be changed to point to the next in the list (as it gets removed)
* (Hopefully all compilers will be happy with the lines with just a space on them. Those are * (Hopefully all compilers will be happy with the lines with just a space on them. Those are
* really just to help this code easier to read) * really just to help this code easier to read)
*/ */
#define SINGLETARGETNS_FLUSH_TARS(con, datatar, ct, list, nocopy) \ #define SINGLETARGETNS_FLUSH_TARS(con, datatar, ct, list, nocopy) \
{ \ { \
if (ct) { \ if (ct) { \
bConstraintTarget *ctn = ct->next; \
if (nocopy == 0) { \ if (nocopy == 0) { \
datatar= ct->tar; \ datatar= ct->tar; \
con->tarspace= ct->space; \ con->tarspace= ct->space; \
} \ } \
\ \
BLI_freelinkN(list, ct); \ BLI_freelinkN(list, ct); \
ct= ctn; \
} \ } \
} }
@@ -1214,7 +1220,6 @@ static void kinematic_flush_tars (bConstraint *con, ListBase *list, short nocopy
/* the following macro is used for all standard single-target constraints */ /* the following macro is used for all standard single-target constraints */
SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy) SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
ct= ct->next;
SINGLETARGET_FLUSH_TARS(con, data->poletar, data->polesubtarget, ct, list, nocopy) SINGLETARGET_FLUSH_TARS(con, data->poletar, data->polesubtarget, ct, list, nocopy)
} }
} }