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

ECS_MODULE throws -> error: taking the address of a temporary object of type 'MODULE_NAME' [-Waddress-of-temporary] #98

Closed
WEREMSOFT opened this issue Nov 1, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@WEREMSOFT
Copy link
Contributor

WEREMSOFT commented Nov 1, 2019

Describe the bug
I'm trying to create modules based on the example file 04_simple_module. I need to use C++

I added a .hhp file in the project, which is the following:

#pragma once
#include "flecs.h"

extern "C" {
    typedef float PositionX;
    typedef float PositionY;

    void MoveX(ecs_rows_t *rows) {
        static double phase = 0;
        static int offset = 0;
        ECS_COLUMN(rows, PositionX, p, 1);
        phase += 10 * rows->delta_time;
        for (int i = 0; i < rows->count; i++) {
            p[i] = sin(phase) * 100 + offset++;
        }
    }

    void MoveY(ecs_rows_t *rows) {
        static double phase = 0;
        static int offset = 0;
        ECS_COLUMN(rows, PositionY, p, 1);
        phase += 10 * rows->delta_time;
        for (int i = 0; i < rows->count; i++) {
            p[i] = cos(phase) * 100 + offset++;
        }
    }

    /* This type is used to store handles to everything that the module contains.
    * When the module is loaded, this type will be registered as component, and
    * added to the singleton entity so applications can access module handles from
    * anywhere. */
    typedef struct MoveModule {
        ECS_DECLARE_COMPONENT(PositionX);
        ECS_DECLARE_COMPONENT(PositionY);
        ECS_DECLARE_ENTITY(MoveX);
        ECS_DECLARE_ENTITY(MoveY);
    } MoveModule;

    /* This macro is used to declare variables that contain the handles inside the
    * module. It is invoked by the ECS_IMPORT macro to declare variables in the
    * scope where the macro is invoked so the contents of the module can be used
    * after the ECS_IMPORT macro. */
    #define MoveModuleImportHandles(handles)\
                ECS_IMPORT_COMPONENT(handles, PositionX);\
                ECS_IMPORT_COMPONENT(handles, PositionY);\
                ECS_IMPORT_ENTITY(handles, MoveX);\
                ECS_IMPORT_ENTITY(handles, MoveY);\

    void MoveModuleImport(
            ecs_world_t *world,
            int flags)
    {
        /* Define module */
        ECS_MODULE(world, MoveModule); // THIS LINE HAS THE ERROR

        /* Register components */
        ECS_COMPONENT(world, PositionX);
        ECS_COMPONENT(world, PositionY);

        /* Define a system called Move that is executed every frame, and subscribes
         * for the 'Position' and 'Velocity' components */
        ECS_SYSTEM(world, MoveX, EcsOnUpdate, PositionX);
        ECS_SYSTEM(world, MoveY, EcsOnUpdate, PositionY);

        /* Export handles to module contents */
        ECS_SET_COMPONENT(PositionX);
        ECS_SET_COMPONENT(PositionY);
        ECS_SET_ENTITY(MoveX);
        ECS_SET_ENTITY(MoveY);
    }
} 

But I have this error in the build:

End of search list.
In file included from /Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/src/main.cpp:5:
/Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/src/MoveModule.hpp:54:9: error: taking the address of a temporary object of type 'MoveModule' [-Waddress-of-temporary]
        ECS_MODULE(world, MoveModule);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/include/flecs.h:2213:5: note: expanded from macro 'ECS_MODULE'
    ecs_set_singleton(world, id, {0});\
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/include/flecs.h:1144:77: note: expanded from macro 'ecs_set_singleton'
    _ecs_set_singleton_ptr(world, ecs_entity(component), sizeof(component), &(component)__VA_ARGS__)
                                                                            ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/src/main.cpp:5:
/Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/src/MoveModule.hpp:54:9: error: cannot initialize a variable of type 'MoveModule *' with an rvalue of type 'void *'
        ECS_MODULE(world, MoveModule);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/pabloweremczuk/Documents/Proyectos/cpp/SFMLFlecs/include/flecs.h:2214:9: note: expanded from macro 'ECS_MODULE'
    id *handles = ecs_get_singleton_ptr(world, id);\
        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

To Reproduce

  1. Create a program.
  2. Create a module.
  3. Try to include the module in the world.

Expected behavior
Handle the systems in the module as a unit.

Additional context
I'm trying to do it in C++, since I'm trying the framework SFML that is in C++. I'm using MacOS X Catalina.
It works well on C99.

@WEREMSOFT WEREMSOFT added the bug Something isn't working label Nov 1, 2019
@SanderMertens
Copy link
Owner

Looks like nobody has ever tried creating a module in C++ before, I'll look into it!

@SanderMertens
Copy link
Owner

@WEREMSOFT checked in a fix for this, closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants