Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CompactInPlace failure #43

Merged
merged 2 commits into from
Feb 1, 2024
Merged

Conversation

amakhno
Copy link

@amakhno amakhno commented Jan 31, 2024

Problem

It turned out that DMesh3.CompactInPlace works correctly only if vertices_refcount, edges_refcount or triangles_refcount buffers have their last value as 0.

If it doesn't, the next required value is out of the boundaries of the array, and it fails.

Solution

Add extra boundaries check for all while loops working with these buffers.

Also, it seems that we can skip iteration over these vectors if we know that they are compact.

Sadly, with whitespace changes VS added spaces in changed expressions.

mesh/DMesh3.cs Outdated
if (!vertices_refcount.is_dense)
{
// find first free vertex, and last used vertex
int iLastV = MaxVertexID - 1, iCurV = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

меня смущает, что iLast устанавливаем как MaxVertexID, но iCurV сравниваем с vertices_refcount.max_index

Copy link
Author

@amakhno amakhno Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тебя зря это смущает, MaxVertexID это

public int MaxVertexID {
	get { return vertices_refcount.max_index; }
}

Но ради прозрачности я сменю на vertices_refcount.max_index явно

mesh/DMesh3.cs Outdated

// move cur forward one, last back one, and then search for next valid
iLastV--; iCurV++;
while (vertices_refcount.isValidUnsafe(iLastV) == false)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

может сюда добавить проверку на iLast >= 0 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У меня были эти мысли, но тут непонятно что лучше. С одной стороны, такая проверка почти во всех случаях избыточна, а актуальна только в некоторых кейсах, которые выглядят как что-то нереалистичное

Добавлю их, на всякий случай

@amakhno amakhno merged commit b2a1961 into softsmile Feb 1, 2024
1 check passed
@amakhno amakhno deleted the fix-compactinplace-indices branch February 1, 2024 09:04
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.

3 participants