Page MenuHome

2.70a - Blender Render - Texture Stack - persistent checkbox state
Closed, ResolvedPublic


System Information
Win7 64bit Radeon HD 68XX

Blender Version

Short description of error
Blender Render -
Newly added textures appears unchecked if the used slot in texture stack was unchecked and deleted previously. Took me some time to figure out why a newly added texture won't be shown.

Is this check box state linked to the stack location somehow ? Should'nt this be reset when a texture was deleted ?

Greetings, Martin

Event Timeline

martin me (martinme) set Type to Bug.
martin me (martinme) created this task.
martin me (martinme) raised the priority of this task from to Needs Triage by Developer.

Here is a small patch that resets 'use' flag of mat texslots, when a new (or existing) texture is assigned to the active slot, which was previously empty.

This change was not as easy as expected, because all this texture handling is a bit fuzzy and spread across the code, and yet quite highly factorized (used for all texslots types, materials, world, particles, etc.).

@Brecht Van Lommel (brecht), would prefer to get your advice on this before I commit.

1diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
2index 4fff501..37bd5fe 100644
3--- a/source/blender/blenkernel/intern/texture.c
4+++ b/source/blender/blenkernel/intern/texture.c
5@@ -705,6 +705,10 @@ MTex *add_mtex_id(ID *id, int slot)
6 MEM_freeN(mtex_ar[slot]);
7 mtex_ar[slot] = NULL;
8 }
9+ else if (GS(id->name) == ID_MA) {
10+ /* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */
11+ ((Material *)id)->septex |= (1 << slot);
12+ }
14 mtex_ar[slot] = add_mtex();
16diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
17index 4166a52..79ab300 100644
18--- a/source/blender/editors/render/render_shading.c
19+++ b/source/blender/editors/render/render_shading.c
20@@ -449,6 +449,13 @@ static int new_texture_exec(bContext *C, wmOperator *UNUSED(op))
21 * pointer se also increases user, so this compensates it */
22 tex->;
24+ if ( && GS(((ID *)>name) == ID_MA &&
25+ RNA_property_pointer_get(&ptr, prop) == NULL) {
26+ /* In case we are assigning new texture to a material, and active slot was empty, reset 'use' flag. */
27+ Material *ma = (Material *);
28+ ma->septex &= ~(1 << ma->texact);
29+ }
31 RNA_id_pointer_create(&tex->id, &idptr);
32 RNA_property_pointer_set(&ptr, prop, idptr);
33 RNA_property_update(C, &ptr, prop);


Note, if this ends up being used elsewhere (as it may be in the future).

if ( && GS(((ID *)>name) == ID_MA ... )

Could be replaced with...

short ptr_idcode = ? GS(((ID *)>name) : -1;
if (ptr_idcode == ID_MA ... )

Could even have some RNA_id_pointer_*** api call to get the idcode though that may be getting too specific.