texture forcefields had a bug where uninitialized values could be used.

do_texture_effector assumed multitex_ext would assign r/g/b colors which isnt true for grey textures.
Fallback to PFIELD_TEX_GRAD with grey textures, node this in tooltip also.
This commit is contained in:
Campbell Barton 2008-02-17 23:53:48 +00:00
parent a207d14958
commit 0fe6abbfa3
3 changed files with 9 additions and 9 deletions

@ -2261,12 +2261,10 @@ static void do_texture_effector(Tex *tex, short mode, short is_2d, float nabla,
{
TexResult result[4];
float tex_co[3], strength, mag_vec[3];
int i;
int hasrgb;
if(tex==NULL) return;
if(tex==0) return;
for(i=0; i<4; i++)
result[i].nor=0;
result[0].nor = result[1].nor = result[2].nor = result[3].nor = 0;
strength= force_val*falloff;///(float)pow((double)distance,(double)power);
@ -2282,9 +2280,9 @@ static void do_texture_effector(Tex *tex, short mode, short is_2d, float nabla,
Mat4Mul3Vecfl(obmat,tex_co);
}
multitex_ext(tex, tex_co, NULL,NULL, 1, result);
hasrgb = multitex_ext(tex, tex_co, NULL,NULL, 1, result);
if(mode==PFIELD_TEX_RGB){
if(hasrgb && mode==PFIELD_TEX_RGB){
mag_vec[0]= (0.5f-result->tr)*strength;
mag_vec[1]= (0.5f-result->tg)*strength;
mag_vec[2]= (0.5f-result->tb)*strength;
@ -2303,7 +2301,7 @@ static void do_texture_effector(Tex *tex, short mode, short is_2d, float nabla,
tex_co[2]+= nabla;
multitex_ext(tex, tex_co, NULL,NULL, 1, result+3);
if(mode==PFIELD_TEX_GRAD){
if(mode==PFIELD_TEX_GRAD || !hasrgb){ /* if we dont have rgb fall back to grad */
mag_vec[0]= (result[0].tin-result[1].tin)*strength;
mag_vec[1]= (result[0].tin-result[2].tin)*strength;
mag_vec[2]= (result[0].tin-result[3].tin)*strength;

@ -1210,6 +1210,8 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex,
return retval;
}
/* Warning, if the texres's values are not declared zero, check the return value to be sure
* the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell */
int multitex_ext(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
{

@ -3429,7 +3429,7 @@ static void object_panel_fields(Object *ob)
uiDefButBitS(block, TOG, PFIELD_GUIDE_PATH_ADD, B_FIELD_CHANGE, "Additive", 10,40,140,20, &pd->flag, 0.0, 0, 0, 0, "Based on distance/falloff it adds a portion of the entire path");
}
else if(pd->forcefield==PFIELD_TEXTURE){
uiDefButS(block, MENU, B_FIELD_CHANGE, "Texture mode%t|RGB%x0|Gradient%x1|Curl%x2", 10,40,140,20, &pd->tex_mode, 0.0, 0.0, 0, 0, "How the texture effect is calculated (RGB & Curl need a RGB texture)");
uiDefButS(block, MENU, B_FIELD_CHANGE, "Texture mode%t|RGB%x0|Gradient%x1|Curl%x2", 10,40,140,20, &pd->tex_mode, 0.0, 0.0, 0, 0, "How the texture effect is calculated (RGB & Curl need a RGB texture else Gradient will be used instead)");
uiDefButF(block, NUM, B_FIELD_CHANGE, "Nabla:", 10,20,140,20, &pd->tex_nabla, 0.0001f, 1.0, 1, 0, "Specify the dimension of the area for gradient and curl calculation");
}