Git Product home page Git Product logo

Comments (6)

alecthomas avatar alecthomas commented on May 27, 2024

What’s the assertion?

from entityx.

felippeduran avatar felippeduran commented on May 27, 2024

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.

alecthomas avatar alecthomas commented on May 27, 2024

Can you provide some sample code? Also are you sure the dwpendency is being added?

from entityx.

felippeduran avatar felippeduran commented on May 27, 2024

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.

felippeduran avatar felippeduran commented on May 27, 2024

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.

alecthomas avatar alecthomas commented on May 27, 2024

That is great to know, thanks. It seems frankly bizarre that statics would be inlined under any circumstances...

from entityx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.