Better fix for #36688.

Throw a python error if user attempts to use CurveMap without calling
CurveMapping.initialize() first. Added access to the initialize function
to CurveMapping on RNA level.

Thanks to Campbel for the help and remarks!
This commit is contained in:
Antony Riakiotakis 2013-09-11 23:28:23 +00:00
parent 494687908c
commit f16047c2df
3 changed files with 13 additions and 16 deletions

View File

@ -64,7 +64,6 @@ void curvemapping_changed_all(struct CurveMapping *cumap);
/* call before _all_ evaluation functions */
void curvemapping_initialize(struct CurveMapping *cumap);
void curvemap_initialize(struct CurveMap *cuma);
/* keep these (const CurveMap) - to help with thread safety */
/* single curve, no table check */

View File

@ -878,19 +878,6 @@ void curvemapping_initialize(CurveMapping *cumap)
}
}
void curvemap_initialize(CurveMap *cuma)
{
if (cuma->table == NULL) {
rctf clipr;
/* clip rectangle is not available here, but we can use a temporary
* rectangle with the same min/max values */
clipr.xmin = cuma->mintable;
clipr.xmax = cuma->maxtable;
curvemap_make_table(cuma, &clipr);
}
}
void curvemapping_table_RGBA(const CurveMapping *cumap, float **array, int *size)
{
int a;

View File

@ -621,12 +621,19 @@ static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
}
/* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
static float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
static float rna_CurveMap_evaluateF(struct CurveMap *cuma, ReportList *reports, float value)
{
curvemap_initialize(cuma);
if (!cuma->table) {
BKE_reportf(reports, RPT_ERROR, "CurveMap table not initialized, call initialize() on CurveMapping owner of the CurveMap");
return 0.0f;
}
return curvemap_evaluateF(cuma, value);
}
static void rna_CurveMap_initialize(struct CurveMapping *cumap)
{
curvemapping_initialize(cumap);
}
#else
static void rna_def_curvemappoint(BlenderRNA *brna)
@ -712,6 +719,7 @@ static void rna_def_curvemap(BlenderRNA *brna)
rna_def_curvemap_points_api(brna, prop);
func = RNA_def_function(srna, "evaluate", "rna_CurveMap_evaluateF");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Evaluate curve at given location");
parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
@ -780,6 +788,9 @@ static void rna_def_curvemapping(BlenderRNA *brna)
func = RNA_def_function(srna, "update", "curvemapping_changed_all");
RNA_def_function_ui_description(func, "Update curve mapping after making changes");
func = RNA_def_function(srna, "initialize", "rna_CurveMap_initialize");
RNA_def_function_ui_description(func, "Initialize curve");
}
static void rna_def_color_ramp_element(BlenderRNA *brna)