Skip to content

Commit

Permalink
ReplaceUnit caused segfaults - suspended its use for now; Fixed a ser…
Browse files Browse the repository at this point in the history
…ious segfault in Runtime
  • Loading branch information
Epixu committed Mar 4, 2024
1 parent 81f6ee8 commit 05a6290
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
24 changes: 22 additions & 2 deletions source/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ namespace Langulus::Entity
Runtime::Runtime(Thing* owner) noexcept
: mOwner {owner} {
VERBOSE(this, ": Initializing...");
// We always prefer 'type' definitions that are in the main
// boundary, to avoid segfaults when unloading libraries from
// mModulesByType - it is indexed by a DMeta
// So we make sure that the base modules are defined here
(void)MetaDataOf<A::PlatformModule>();
(void)MetaDataOf<A::PhysicalModule>();
(void)MetaDataOf<A::UI::Module>();
(void)MetaDataOf<A::FileSystem>();
(void)MetaDataOf<A::GraphicsModule>();
(void)MetaDataOf<A::AssetModule>();
VERBOSE(this, ": Initialized");
}

Expand Down Expand Up @@ -125,8 +135,16 @@ namespace Langulus::Entity
auto found = map.FindIt(type);
if (found)
*found.mValue << module;
else
map.Insert(type, module);
else {
// We always prefer 'type' definition that is in the main
// boundary, to avoid segfaults when unloading libraries from
// mModulesByType - it is indexed by a DMeta
auto localDefinition = RTTI::GetMetaData(type->mToken, RTTI::MainBoundary);
if (localDefinition)
map.Insert(localDefinition, module);
else
map.Insert(type, module);
}

for (auto& base : type->mBases) {
if (base.mType->IsExact<Resolvable>())
Expand Down Expand Up @@ -219,6 +237,7 @@ namespace Langulus::Entity
/// with `LangulusMod`, and suffixing with `.so` or `.dll`
/// the name also should correspond to the RTTI::Boundary
/// @return the module handle (OS dependent)
LANGULUS(NOINLINE)
Runtime::SharedLibrary Runtime::LoadSharedLibrary(const Token& name) {
// Check if this library is already loaded
const auto preloaded = mLibraries.FindIt(name);
Expand Down Expand Up @@ -384,6 +403,7 @@ namespace Langulus::Entity
/// Unload a DLL/SO extension module
/// @param library - the library handle to unload
/// @return true if shared library was unloaded successfully
LANGULUS(NOINLINE)
bool Runtime::UnloadSharedLibrary(const SharedLibrary& library) {
if (library.mHandle == 0)
return true;
Expand Down
4 changes: 2 additions & 2 deletions source/Thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ namespace Langulus::Entity
/// @attention assumes both units are different and not nullptr
/// @param replaceThis - the unit to replace
/// @param withThis - the unit to replace with
Count Thing::ReplaceUnit(Unit* replaceThis, Unit* withThis) {
/*Count Thing::ReplaceUnit(Unit* replaceThis, Unit* withThis) {
RemoveUnit(replaceThis);
return AddUnit(withThis);
}
}*/

/// Count the number of matching units in this entity
/// @param type - the type of units to search for
Expand Down
4 changes: 2 additions & 2 deletions source/Thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ namespace Langulus::Entity
template<CT::Unit T = Unit, bool TWOSIDED = true>
Count RemoveUnits();

LANGULUS_API(ENTITY)
Count ReplaceUnit(Unit*, Unit*);
/*LANGULUS_API(ENTITY)
Count ReplaceUnit(Unit*, Unit*);*/

NOD() LANGULUS_API(ENTITY)
Count HasUnits(DMeta) const;
Expand Down
10 changes: 6 additions & 4 deletions source/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Unit::Unit(Unit&& other) noexcept
: Resolvable {Forward<Resolvable>(other)}
, mOwners {::std::move(other.mOwners)} {
// Replace the owner's unit pointer with the new one
for (auto owner : mOwners)
owner->ReplaceUnit(&other, this);
TODO();
/*for (auto owner : mOwners)
owner->ReplaceUnit(&other, this);*/
}

/// Unit destruction
Expand Down Expand Up @@ -77,8 +78,9 @@ Unit& Unit::operator = (Unit&& other) noexcept {
mOwners = Move(other.mOwners);

// Update all coupled owners
for (auto owner : mOwners)
owner->ReplaceUnit(&other, this);
TODO();
/*for (auto owner : mOwners)
owner->ReplaceUnit(&other, this);*/
return *this;
}

Expand Down
4 changes: 2 additions & 2 deletions test/TestThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ SCENARIO("Testing Thing", "[thing]") {
REQUIRE(nullptr == Allocator::Find(MetaOf<TestUnit2>(), unitmemory2));
}

WHEN("Replace local units") {
/*WHEN("Replace local units") {
TestUnit2 replacement;
auto replaced = root.ReplaceUnit(root.GetUnit<TestUnit1>(), &replacement);
REQUIRE(replaced == 1);
REQUIRE(root.mUnitsList.GetCount() == 2);
REQUIRE(root.mUnitsAmbiguous[MetaOf<TestUnit2>()].GetCount() == 2);
REQUIRE(root.mUnitsAmbiguous[MetaOf<TestUnit2>()].Contains(&replacement));
}
}*/

WHEN("Count available units") {
auto found = root.HasUnits<TestUnit1>();
Expand Down

0 comments on commit 05a6290

Please sign in to comment.