Skip to content

BSTriShape.SetUVs: write to rawUvs (UVs), not rawUVs (tangents)#25

Merged
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/bstrishape-setuvs-buffer
Apr 25, 2026
Merged

BSTriShape.SetUVs: write to rawUvs (UVs), not rawUVs (tangents)#25
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/bstrishape-setuvs-buffer

Conversation

@MANOLOV02
Copy link
Copy Markdown
Contributor

SetUVs has two write paths that both target rawUVs (capital V). Per the field comments, rawUVs is the cached tangent buffer (Vector3[]) and rawUvs (lowercase v) is the actual UV buffer (TexCoord[]). The capital-V usage looks like a copy-paste from SetTangents. UV writes silently mutate the cached tangent list instead.

Impact is partially masked because the public UVs getter regenerates from VertexData, but the cached Tangents list ends up contaminated and any consumer reading it directly sees garbage.

C++ reference: nifly/Geometry.cpp:658 (rawTangents) and :690 (rawUvs) — the C++ uses unambiguous names that don't collide.

Fix: change both write sites to rawUvs.

Maps to issue #15 item F14.

MANOLOV02 and others added 2 commits April 25, 2026 17:46
BSTriShape has two internal buffers with near-identical names:
  rawUVs (capital V)  — List<Vector3>, tangent buffer (filled by
                        UpdateRawTangents)
  rawUvs (lowercase v)— List<TexCoord>, UV buffer (filled by
                        UpdateRawUvs)

SetUVs(...) was resizing/writing to `rawUVs` (the tangent buffer),
silently corrupting tangents on every SetUVs call. The real UV buffer
`rawUvs` was left untouched.

Impact is partial in practice because .Tangents/.UVs accessors
regenerate both buffers from the canonical vertData at read time, so
the sin-set intermediate state was rarely observed, but any code that
read `rawUVs` directly between SetUVs and the next Update* call got
garbage.

C++ nifly avoids the collision with unambiguous names: `rawTangents`
(Geometry.cpp:658) and `rawUvs` (Geometry.cpp:690).
@ousnius ousnius merged commit 8b69893 into ousnius:main Apr 25, 2026
1 check passed
@MANOLOV02 MANOLOV02 deleted the fix/bstrishape-setuvs-buffer branch April 25, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants