Skip to content

RenderState: Setters Missing Hash Invalidation #2593

@capdevon

Description

@capdevon

The following fields are part of the contentHashCode() computation:

hash = 79 * hash + this.frontStencilMask;
hash = 79 * hash + this.frontStencilReference;
hash = 79 * hash + this.backStencilMask;
hash = 79 * hash + this.backStencilReference;

However, their corresponding setters do not set cachedHashCode = -1:

public void setFrontStencilMask(int frontStencilMask) {
    this.frontStencilMask = frontStencilMask;
}

public void setBackStencilMask(int backStencilMask) {
    this.backStencilMask = backStencilMask;
}

public void setFrontStencilReference(int frontStencilReference) {
    this.frontStencilReference = frontStencilReference;
}

public void setBackStencilReference(int backStencilReference) {
    this.backStencilReference = backStencilReference;
}

Since these fields directly contribute to the hash, modifying them without invalidating the cached hash results in an inconsistent RenderState.

Expected Fix
Each setter should follow the same pattern used in correctly implemented methods such as setColorWrite:

public void setColorWrite(boolean colorWrite) {
    applyColorWrite = true;
    this.colorWrite = colorWrite;
    cachedHashCode = -1;
}

This ensures that contentHashCode() always reflects the actual state of the object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions