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

Crash after recreating an entity #76

Closed
SlyF0Xx opened this issue Jan 24, 2022 · 2 comments · Fixed by #77
Closed

Crash after recreating an entity #76

SlyF0Xx opened this issue Jan 24, 2022 · 2 comments · Fixed by #77

Comments

@SlyF0Xx
Copy link

SlyF0Xx commented Jan 24, 2022

While working on physics system using Edyn for my engine, I see, that deleting an entity will lead to crash after creating new entity and run simulation
I tried to write minimal reproducible example - here it is

#include <entt/entt.hpp>
#include "edyn/edyn.hpp"

#include <iostream>

int main()
{
	entt::registry registry;

	edyn::init();
	edyn::attach(registry);

	// Create floor
	auto floor_def = edyn::rigidbody_def();
	floor_def.kind = edyn::rigidbody_kind::rb_static;
	floor_def.shape = edyn::plane_shape{ {0, 1, 0}, 0 };
	auto entity = edyn::make_rigidbody(registry, floor_def);

	registry.destroy(entity);

	auto entity2 = edyn::make_rigidbody(registry, floor_def);
	edyn::update(registry);
}

In console I see

Assertion failed: valid(entity), file C:\src\vcpkg\installed\x64-windows\include\entt/entity/registry.hpp, line 895

Callstack of the crash

 	ucrtbased.dll!issue_debug_notification(const wchar_t * const message) Line 28	C++
 	ucrtbased.dll!__acrt_report_runtime_error(const wchar_t * message) Line 154	C++
 	ucrtbased.dll!abort() Line 61	C++
 	ucrtbased.dll!common_assert_to_stderr_direct(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number) Line 161	C++
 	ucrtbased.dll!common_assert_to_stderr<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number) Line 179	C++
 	ucrtbased.dll!common_assert<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number, void * const return_address) Line 420	C++
 	ucrtbased.dll!_wassert(const wchar_t * expression, const wchar_t * file_name, unsigned int line_number) Line 444	C++
>	ConsoleApplication4.exe!entt::basic_registry<enum entt::entity>::any_of<edyn::procedural_tag>(const entt::entity entity) Line 895	C++
 	ConsoleApplication4.exe!edyn::island_coordinator::init_new_nodes_and_edges() Line 167	C++
 	ConsoleApplication4.exe!edyn::island_coordinator::update() Line 803	C++
 	ConsoleApplication4.exe!edyn::update(entt::basic_registry<enum entt::entity> & registry) Line 67	C++
 	ConsoleApplication4.exe!main() Line 26	C++
 	[External Code]	

Edyn is build from sources from 4e497d7 commit

@xissburg
Copy link
Owner

xissburg commented Jan 25, 2022

You must not reuse an entity after it's destroyed using registry.destroy(entity), as it becomes an invalid entity identifier. You have to create a new entity using registry.create().

@xissburg
Copy link
Owner

xissburg commented Jan 25, 2022

Oh sorry, I misread your code. I'll have to investigate further I guess. That looks like a bug in edyn::island_coordinator where it accumulates entities for later initialization, and there's the possibility that the entity was destroyed before being initialized in the call to edyn::update.

xissburg added a commit that referenced this issue Jan 26, 2022
@xissburg xissburg mentioned this issue Jan 26, 2022
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 a pull request may close this issue.

2 participants