Skip to content

Fix TriangleVertexArray.cpp compilation warning #427

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kejoko
Copy link

@Kejoko Kejoko commented Jul 24, 2025

When attempting to compile with -Wreturn-type and -Werror flags we get the following error:

Building CXX object my_repo/reactphysics3d.dir/src/collision/TriangleVertexArray.cpp.o
/Users/my_name/my_repo/reactphysics3d/src/collision/TriangleVertexArray.cpp:163:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
  163 | }
      | ^

This is because the end of the TriangleVertexArray::getVertex function doesn't have a return statement outside of the else block (which realistically will never get reached, but the compiler still complains). Adding the return Vector3::zero() line fixes the issue:

Vector3 TriangleVertexArray::getVertex(uint32 vertexIndex) const {
    ...

    if (mVertexDataType == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE) {
        ...
        return Vector3(decimal(vertices[0]), decimal(vertices[1]), decimal(vertices[2]));
    }
    else if (mVertexDataType == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE) {
        ...
        return Vector3(decimal(vertices[0]), decimal(vertices[1]), decimal(vertices[2]));
    }
    else {
        assert(false);
    }

    return Vector3::zero();
}

This change makes the TriangleVertexArray::getVertex function follow the same return flow as the TriangleVertexArray::getVertex function:

Vector3 TriangleVertexArray::getVertexNormal(uint32 vertexIndex) const {
    ...

    if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE) {
        ...
        return Vector3(decimal(normal[0]), decimal(normal[1]), decimal(normal[2]));
    }
    else if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_DOUBLE_TYPE) {
        ...
        return Vector3(decimal(normal[0]), decimal(normal[1]), decimal(normal[2]));
    }
    else {
        assert(false);
    }

    return Vector3::zero();
}

@Kejoko Kejoko changed the title Fix the compilation error Fix TriangleVertexArray.cpp compilation warning Jul 24, 2025
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.

1 participant