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

Stack cookie instrumentation code detected a stack-based buffer overrun. in VS2019 #82

Closed
RallyTronics opened this issue Apr 8, 2022 · 16 comments

Comments

@RallyTronics
Copy link

I am using version 1.0.0
VS2019 debug build

When the shared_components dynamic initializer ( in shared_comp.h ) executes at startup I get a stack-based buffer overrun exception. Has anyone else run into this?

@xissburg
Copy link
Owner

xissburg commented Apr 8, 2022

That looks like a more fundamental problem which is likely not related to the shared_components tuple. More information is needed. Are you linking the library (static or dynamic?) against your own application?

@RallyTronics
Copy link
Author

I am linking statically against my own application ( 64 bit )

entt::registry reg;

int main(void)
{
    edyn::init();
    edyn::attach(reg);

    auto def = edyn::rigidbody_def();
    def.kind = edyn::rigidbody_kind::rb_dynamic;
    def.position = { 0, 3, 0 };
    def.orientation = edyn::quaternion_axis_angle({ 0, 1, 0 }, edyn::to_radians(30));
    def.linvel = edyn::vector3_zero;
    def.angvel = { 0, 0.314, 0 };
    def.mass = 50;
    def.shape = edyn::box_shape{ 0.5, 0.2, 0.4 }; // Shape is optional.
    def.update_inertia();
    def.material->restitution = 0.2; // Material is also optional.
    def.material->friction = 0.9;
    def.gravity = edyn::gravity_earth;
    auto entity = edyn::make_rigidbody(reg, def);

    while (1)
    {
        edyn::update(reg);

        auto rigid_bodies = reg.view<edyn::present_position, edyn::present_orientation>();

        for (auto rb : rigid_bodies)
        {
            auto& pp = rigid_bodies.get<edyn::present_position>(rb);
            auto& po = rigid_bodies.get<edyn::present_orientation>(rb);

            std::cout << "pos: (" << pp.x << ',' << pp.y << ',' << pp.z << ")  ori: " << edyn::quaternion_angle(po) << "\n";
        }
    }
    return 0;
}

@xissburg
Copy link
Owner

xissburg commented Apr 9, 2022

It looks alright. I can't give any additional advice without more information.

@RallyTronics
Copy link
Author

It appears that shared_components is getting initialized multiple times, it crashes on the second initialization. I am still trying to figure out why.

@xissburg
Copy link
Owner

Hmm interesting... shared_components is declared as static const in a header. That might be a problem... I will have to investigate.

@xissburg
Copy link
Owner

I have pushed some changes to master. Let me know if that fixes it.

@RallyTronics
Copy link
Author

I have a ton of errors trying to build master regarding the matrix3x3 class

edyn/math/matrix3x3.hpp(25,23): error C3615: constexpr function 'edyn::matrix3x3::column' cannot result in a constant expression
edyn/math/matrix3x3.hpp(26,25): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(26,25): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(26,36): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(26,36): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(26,47): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(26,47): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(29,22): error C3615: constexpr function 'edyn::matrix3x3::column_dot' cannot result in a constant expression
edyn/math/matrix3x3.hpp(30,24): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(30,24): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(30,42): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(30,42): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(30,60): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(30,60): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(101,16): error C3615: constexpr function 'edyn::operator ==' cannot result in a constant expression
edyn/math/matrix3x3.hpp(102,18): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(102,18): message : see usage of 'std::operator =='
edyn/math/matrix3x3.hpp(106,16): error C3615: constexpr function 'edyn::operator !=' cannot result in a constant expression
edyn/math/matrix3x3.hpp(107,18): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(107,18): message : see usage of 'std::operator !='
edyn/math/matrix3x3.hpp(149,21): error C3615: constexpr function 'edyn::inverse_matrix_symmetric' cannot result in a constant expression
edyn/math/matrix3x3.hpp(150,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(150,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(150,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(150,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(151,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(151,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(151,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(151,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(152,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(152,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(152,5): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(152,5): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(158,22): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(158,22): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(158,37): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(158,37): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(158,52): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(158,52): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(159,22): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(159,22): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(159,37): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(159,37): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(160,22): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(160,22): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(164,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(164,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(165,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(165,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(166,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(166,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(168,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(168,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(168,29): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(168,29): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(169,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(169,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(170,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(170,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(172,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(172,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(172,29): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(172,29): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(173,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(173,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(173,29): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(173,29): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(174,15): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(174,15): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(188,19): error C3615: constexpr function 'edyn::get_diagonal' cannot result in a constant expression
edyn/math/matrix3x3.hpp(189,19): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(189,19): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(189,28): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(189,28): message : see usage of 'edyn::vector3::operator []'
edyn/math/matrix3x3.hpp(189,37): message : failure was caused by call of undefined function or one not declared 'constexpr'
edyn/math/matrix3x3.hpp(189,37): message : see usage of 'edyn::vector3::operator []'


@RallyTronics
Copy link
Author

If declare the vector3 array operators as constexpr

    constexpr scalar& operator[](size_t i) noexcept {
        EDYN_ASSERT(i < 3);
        return (&x)[i];
    }

    constexpr scalar operator[](size_t i) const noexcept {
        EDYN_ASSERT(i < 3);
        return (&x)[i];
    }

I get it down to 2 errors:

math/matrix3x3.hpp(101,16): error C3615: constexpr function 'edyn::operator ==' cannot result in a constant expression
math/matrix3x3.hpp(102,18): message : failure was caused by call of undefined function or one not declared 'constexpr'
math/matrix3x3.hpp(102,18): message : see usage of 'std::operator =='
math/matrix3x3.hpp(106,16): error C3615: constexpr function 'edyn::operator !=' cannot result in a constant expression
math/matrix3x3.hpp(107,18): message : failure was caused by call of undefined function or one not declared 'constexpr'
math/matrix3x3.hpp(107,18): message : see usage of 'std::operator !='

@xissburg
Copy link
Owner

@StellaSmith do you think this is caused by the std::array equality operator? As it is not constexpr before C++20 https://en.cppreference.com/w/cpp/container/array/operator_cmp and it is used in theedyn::matrix3x3 equality operator. It could be replaced by an individual comparison between row vectors.

@StellaSmith
Copy link
Contributor

StellaSmith commented Apr 12, 2022

I would've guessed that std::array had a constexpr equality operator by C++17 but seems i guessed wrong.
Removing constexpr in edyn::matrix3x3::operator== should be the easiest fix, but std::array<T>::operator[] is constexpr so you can compare all the rows manually.

@StellaSmith
Copy link
Contributor

StellaSmith commented Apr 12, 2022

Another thing: edyn::matrix3x3::column(_dot) shouldn't be constexpr since they use edyn::vector3::operator[].

Overnight on my part, my bad.

@xissburg
Copy link
Owner

@RallyTronics let me know if the latest commit changes anything.

@RallyTronics
Copy link
Author

The vector3 array operator [] is still not constexpr so I still get a ton of errors. If I declare those as constexpr it builds correctly. I no longer get the stack-based buffer overrun error. It now crashes in make_rigidbody() here:

    if (def.presentation && def.kind == rigidbody_kind::rb_dynamic) {
        registry.emplace<present_position>(entity, def.position);
        registry.emplace<present_orientation>(entity, def.orientation);
    }

I get an exception on the
registry.emplace<present_position>(entity, def.position);
line. I am still digging.

@RallyTronics
Copy link
Author

Exception occurs here in delegate.hpp
    /**
     * @brief Triggers a delegate.
     *
     * The delegate invokes the underlying function and returns the result.
     *
     * @warning
     * Attempting to trigger an invalid delegate results in undefined
     * behavior.
     *
     * @param args Arguments to use to invoke the underlying function.
     * @return The value returned by the underlying function.
     */
    Ret operator()(Args... args) const {
        ENTT_ASSERT(static_cast<bool>(*this), "Uninitialized delegate");
        return fn(data, std::forward<Args>(args)...);
    }

@RallyTronics
Copy link
Author

RallyTronics commented Apr 13, 2022

I get the same exception when running the hello_world example.

@RallyTronics
Copy link
Author

Closing this as the exception I am getting is separate from the original issue.

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

No branches or pull requests

3 participants