Comments (6)
What’s the assertion?
from entityx.
Thanks for the reply, @alecthomas!
The assertion says that the entity doesn’t have ComponentA
. As the Event::family()
changes between the time the dependency is created (within the shared library) and the time ComponentB
is assigned to the entity (editor code), the event notification fails and EntityX doesn’t assign ComponentA
automatically.
To be more descriptive about the code organisation, EntityX is compiled as a shared library. The engine code too, which uses the EntityX shared library, and the editor code uses both shared libraries.
from entityx.
Can you provide some sample code? Also are you sure the dwpendency is being added?
from entityx.
Hi, @alecthomas
Here's the sample code to reproduce the issue. It seems to be working properly when I compile it by hand (using clang or g++). The issue only occurs when I compile it as a XCode project/workspace, so I'm suspecting it might be related to some compiler configuration or XCode setup.
GameEngine.h:
#include "entityx/entityx.h"
struct ComponentA {
int a;
};
struct ComponentB {
int b;
};
class GameEngine : public entityx::EntityX {
public:
// explicit GameEngine();
// ~GameEngine();
void initialize();
void configure();
int start();
void update(entityx::TimeDelta dt);
};
struct DummySystem : public entityx::System<DummySystem> {
void update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt) override {};
};
GameEngine.cpp:
#include "Engine.h"
#include "entityx/deps/Dependencies.h"
using namespace entityx;
void GameEngine::initialize() {
systems.add<deps::Dependency<ComponentB, ComponentA>>();
systems.add<DummySystem>();
}
void GameEngine::configure() {
systems.configure();
}
main.cpp:
#include <iostream>
#include "entityx.h"
#include "Engine.h"
using namespace std;
using namespace entityx;
void setup();
GameEngine engine;
struct DummySystem2 : public entityx::System<DummySystem2> {
void update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt) override {};
};
int main(int argc, const char *argv[])
{
engine.initialize();
engine.systems.add<DummySystem2>();
engine.configure();
setup();
return 0;
}
void setup()
{
Entity entity = engine.entities.create();
entity.assign<ComponentB>();
printf("Entity has ComponentA: %d\n", entity.has_component<ComponentA>());
entity.component<ComponentA>()->a = 10; // This should throw an assert
}
The first two files belong to the engine and are compiled as a separate dynamic library. The third file, main.cpp
, is compiled as an executable that links to the engine library. Both binaries link to an EntityX dynamic library.
from entityx.
Alright, so I finally managed to reproduce the issue outside XCode and fix it within the XCode project. The whole issue is caused by the compiler flag -fvisibility-inlines-hidden
, which is enabled by default in XCode.
It seems that this flag was hiding the definition of the static variable family
from each event template implementation (and maybe system) between shared objects. In the end, the issue was not related to the family_counter
, but the family
instead (which is now pretty obvious). I've also found an explanation of this behaviour in greater detail in this stackoverflow answer.
After I changed EntityX from a static library to a dynamic one, I was expecting that it would fix all problems related to duplicate memory addresses, but that was not the case and it bugged me!
Thanks for the help anyway, @alecthomas!
Hope this thread might be useful to other people in the future!
from entityx.
That is great to know, thanks. It seems frankly bizarre that statics would be inlined under any circumstances...
from entityx.
Related Issues (20)
- Cross compile with target_complie_feature error HOT 2
- Assertion failed when trying to add system HOT 3
- Assertion failure when removing a component while an entity is being destroyed
- UUIDCollisionResolver HOT 2
- Assigning Component in Update Loop Crashes HOT 3
- [Question] Select components based on a specific variable value HOT 1
- Can't use entityx in Qt : conflicts with simplesignal HOT 2
- Some little requests~
- Future of entityx HOT 5
- more efficient way of looping trough a bunch of classes? HOT 1
- Passing an entity as a pointer (Question) HOT 11
- Catch::AssertionInfo& Issues Preventing Build HOT 1
- Inherited Component Polymorphism? HOT 2
- Grabbing access to the entity that owns a component? HOT 1
- Inheriting from Entity? HOT 1
- Issue with install from vcpkg
- Shared library not working in Windows HOT 1
- Entity creation / destruction slows down over time? HOT 15
- Does this project have DOP optimization? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityx.