Skip to content

Commit

Permalink
Fix destruction of entities not being done properly due to initializa…
Browse files Browse the repository at this point in the history
…tion order of globals.
  • Loading branch information
daid committed Oct 27, 2022
1 parent be84d36 commit c6ebd57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ecs/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace sp::ecs {

static std::vector<ComponentStorageBase*> all_component_storage;
static ComponentStorageBase* all_component_storage = nullptr;

ComponentStorageBase::ComponentStorageBase()
{
all_component_storage.push_back(this);
this->next = all_component_storage;
all_component_storage = this;
}

void ComponentStorageBase::destroyAll(uint32_t index)
{
for(auto storage : all_component_storage)
for(auto storage = all_component_storage; storage; storage = storage->next)
storage->destroy(index);
}

Expand Down
2 changes: 2 additions & 0 deletions src/ecs/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ComponentStorageBase {
public:
ComponentStorageBase();

private:
ComponentStorageBase* next = nullptr;
protected:
static void destroyAll(uint32_t index);
virtual void destroy(uint32_t index) = 0;
Expand Down

1 comment on commit c6ebd57

@daid-tinyci
Copy link

@daid-tinyci daid-tinyci bot commented on c6ebd57 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TinyCI build failure:

[/home/tinyci/builds/daid/SeriousProton/_build_native:make -j 2] returned [2]:


[ 15%] Built target spfreetype2

[ 16%] Built target glad

[ 29%] Built target box2d

[ 37%] Built target lua

[ 43%] Built target basisu-encoder

[ 83%] Built target opus

[ 84%] Building CXX object CMakeFiles/seriousproton_objects.dir/src/ecs/entity.cpp.o

[ 84%] Building CXX object CMakeFiles/seriousproton_objects.dir/src/ecs/component.cpp.o

In file included from /data/tinyci_builds/daid/SeriousProton/src/ecs/component.h:3,

                 from /data/tinyci_builds/daid/SeriousProton/src/ecs/entity.h:6,

                 from /data/tinyci_builds/daid/SeriousProton/src/ecs/entity.cpp:1:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:60:35: error: ‘size_t’ has not been declared

   60 |         Iterator(SparseSet& _set, size_t _dense_index) : set(_set), dense_index(_dense_index) {}

      |                                   ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:70:9: error: ‘size_t’ does not name a type

   70 |         size_t dense_index;

      |         ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:5:1: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?

    4 | #include <vector>

  +++ |+#include <cstddef>

    5 | #include <limits>

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In constructor ‘sp::SparseSet<T>::Iterator::Iterator(sp::SparseSet<T>&, int)’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:60:69: error: class ‘sp::SparseSet<T>::Iterator’ does not have any field named ‘dense_index’

   60 |         Iterator(SparseSet& _set, size_t _dense_index) : set(_set), dense_index(_dense_index) {}

      |                                                                     ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘bool sp::SparseSet<T>::Iterator::operator!=(const sp::SparseSet<T>::Iterator&) const’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:62:63: error: ‘dense_index’ was not declared in this scope

   62 |         bool operator!=(const Iterator& other) const { return dense_index != other.dense_index; }

      |                                                               ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘void sp::SparseSet<T>::Iterator::operator++()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:63:29: error: ‘dense_index’ was not declared in this scope

   63 |         void operator++() { dense_index--; }

      |                             ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘std::pair<unsigned int, T&> sp::SparseSet<T>::Iterator::operator*()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:64:65: error: ‘dense_index’ was not declared in this scope

   64 |         std::pair<uint32_t, T&> operator*() { return {set.dense[dense_index], set.data[dense_index]}; }

      |                                                                 ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘std::pair<unsigned int, const T&> sp::SparseSet<T>::Iterator::operator*() const’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:65:77: error: ‘dense_index’ was not declared in this scope

   65 |         std::pair<uint32_t, const T&> operator*() const { return {set.dense[dense_index], set.data[dense_index]}; }

      |                                                                             ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘bool sp::SparseSet<T>::Iterator::atEnd()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:31: error: ‘dense_index’ was not declared in this scope

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                               ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:66: error: ‘size_t’ was not declared in this scope; did you mean ‘std::size_t’?

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                                                                  ^~~~~~

      |                                                                  std::size_t

In file included from /usr/include/c++/12/limits:42,

                 from /data/tinyci_builds/daid/SeriousProton/src/ecs/entity.h:4:

/usr/include/x86_64-linux-gnu/c++/12/bits/c++config.h:298:33: note: ‘std::size_t’ declared here

  298 |   typedef __SIZE_TYPE__         size_t;

      |                                 ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:72: error: template argument 1 is invalid

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                                                                        ^

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘sp::SparseSet<T>::Iterator sp::SparseSet<T>::end()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:74:65: error: ‘size_t’ was not declared in this scope; did you mean ‘std::size_t’?

   74 |     Iterator end() { return Iterator(*this, std::numeric_limits<size_t>::max()); }

      |                                                                 ^~~~~~

      |                                                                 std::size_t

/usr/include/x86_64-linux-gnu/c++/12/bits/c++config.h:298:33: note: ‘std::size_t’ declared here

  298 |   typedef __SIZE_TYPE__         size_t;

      |                                 ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:74:71: error: template argument 1 is invalid

   74 |     Iterator end() { return Iterator(*this, std::numeric_limits<size_t>::max()); }

      |                                                                       ^

In file included from /data/tinyci_builds/daid/SeriousProton/src/ecs/component.h:3,

                 from /data/tinyci_builds/daid/SeriousProton/src/ecs/component.cpp:1:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:60:35: error: ‘size_t’ has not been declared

   60 |         Iterator(SparseSet& _set, size_t _dense_index) : set(_set), dense_index(_dense_index) {}

      |                                   ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:70:9: error: ‘size_t’ does not name a type

   70 |         size_t dense_index;

      |         ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:6:1: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?

    5 | #include <limits>

  +++ |+#include <cstddef>

    6 | 

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In constructor ‘sp::SparseSet<T>::Iterator::Iterator(sp::SparseSet<T>&, int)’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:60:69: error: class ‘sp::SparseSet<T>::Iterator’ does not have any field named ‘dense_index’

   60 |         Iterator(SparseSet& _set, size_t _dense_index) : set(_set), dense_index(_dense_index) {}

      |                                                                     ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘bool sp::SparseSet<T>::Iterator::operator!=(const sp::SparseSet<T>::Iterator&) const’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:62:63: error: ‘dense_index’ was not declared in this scope

   62 |         bool operator!=(const Iterator& other) const { return dense_index != other.dense_index; }

      |                                                               ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘void sp::SparseSet<T>::Iterator::operator++()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:63:29: error: ‘dense_index’ was not declared in this scope

   63 |         void operator++() { dense_index--; }

      |                             ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘std::pair<unsigned int, T&> sp::SparseSet<T>::Iterator::operator*()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:64:65: error: ‘dense_index’ was not declared in this scope

   64 |         std::pair<uint32_t, T&> operator*() { return {set.dense[dense_index], set.data[dense_index]}; }

      |                                                                 ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘std::pair<unsigned int, const T&> sp::SparseSet<T>::Iterator::operator*() const’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:65:77: error: ‘dense_index’ was not declared in this scope

   65 |         std::pair<uint32_t, const T&> operator*() const { return {set.dense[dense_index], set.data[dense_index]}; }

      |                                                                             ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘bool sp::SparseSet<T>::Iterator::atEnd()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:31: error: ‘dense_index’ was not declared in this scope

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                               ^~~~~~~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:66: error: ‘size_t’ was not declared in this scope; did you mean ‘std::size_t’?

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                                                                  ^~~~~~

      |                                                                  std::size_t

In file included from /usr/include/c++/12/bits/stl_algobase.h:59,

                 from /usr/include/c++/12/vector:60,

                 from /data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:4:

/usr/include/x86_64-linux-gnu/c++/12/bits/c++config.h:298:33: note: ‘std::size_t’ declared here

  298 |   typedef __SIZE_TYPE__         size_t;

      |                                 ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:67:72: error: template argument 1 is invalid

   67 |         bool atEnd() { return dense_index == std::numeric_limits<size_t>::max(); }

      |                                                                        ^

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h: In member function ‘sp::SparseSet<T>::Iterator sp::SparseSet<T>::end()’:

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:74:65: error: ‘size_t’ was not declared in this scope; did you mean ‘std::size_t’?

   74 |     Iterator end() { return Iterator(*this, std::numeric_limits<size_t>::max()); }

      |                                                                 ^~~~~~

      |                                                                 std::size_t

/usr/include/x86_64-linux-gnu/c++/12/bits/c++config.h:298:33: note: ‘std::size_t’ declared here

  298 |   typedef __SIZE_TYPE__         size_t;

      |                                 ^~~~~~

/data/tinyci_builds/daid/SeriousProton/src/container/sparseset.h:74:71: error: template argument 1 is invalid

   74 |     Iterator end() { return Iterator(*this, std::numeric_limits<size_t>::max()); }

      |                                                                       ^

make[2]: *** [CMakeFiles/seriousproton_objects.dir/build.make:866: CMakeFiles/seriousproton_objects.dir/src/ecs/entity.cpp.o] Error 1

make[2]: *** Waiting for unfinished jobs....

make[2]: *** [CMakeFiles/seriousproton_objects.dir/build.make:880: CMakeFiles/seriousproton_objects.dir/src/ecs/component.cpp.o] Error 1

make[1]: *** [CMakeFiles/Makefile2:238: CMakeFiles/seriousproton_objects.dir/all] Error 2

make: *** [Makefile:136: all] Error 2

Please sign in to comment.