Skip to content

References aren't nullable in ISO C++ #22

Description

@psygate

Issue:

The documentation in mesh.h maybe wrong, or the documentation is correct and the chosen type (MatrixX&, Reference Type) is wrong. References can't be null by the C++ standard, and if they are this may lead to undefined behaviour.

See https://en.cppreference.com/w/cpp/language/reference_initialization and https://en.cppreference.com/w/cpp/language/reference

How to reproduce the bug:

`

	const auto m_N(lRec.mesh->getVertexNormals());

	std::cout << m_N(0) << std::endl;

	return { 0.0f };

`

This crashes with an AccessViolationException@NULL, which can't or shouldn't happen with references, since they can't be null.

Solution:

Change the reference to a ptr type (MatrixX*) or change the MatrixX to be an empty matrix and provide a function to check whether normals exist (bool hasVertexNormals() for instance).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions