Skip to content

Commit

Permalink
fix: check m_pClassInfo for nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
es3n1n committed Sep 10, 2024
1 parent 15d1eb1 commit 9257deb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions source2gen/src/sdk/sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ namespace {
} while (pClass != nullptr);
}

const auto has_non_standard_layout_field =
std::ranges::any_of(class_.GetFields() | std::ranges::views::transform([&](const SchemaClassFieldData_t& e) {
if (const auto* e_class = e.m_pSchemaType->GetAsDeclaredClass(); e_class != nullptr) {
return !IsStandardLayoutClass(cache, *e_class->m_pClassInfo);
} else {
// Everything that is not a class has no effect
return false;
}
}),
std::identity{});
const auto has_non_standard_layout_field = std::ranges::any_of(
class_.GetFields() | std::ranges::views::transform([&](const SchemaClassFieldData_t& e) {
if (const auto* e_class = e.m_pSchemaType->GetAsDeclaredClass(); e_class != nullptr && e_class->m_pClassInfo != nullptr) {
return !IsStandardLayoutClass(cache, *e_class->m_pClassInfo);
} else {
// Everything that is not a class has no effect
return false;
}
}),
std::identity{});

if (has_non_standard_layout_field) {
return cache.emplace(id, false).first->second;
Expand Down Expand Up @@ -281,7 +281,7 @@ namespace {
/// @return For class types, returns @ref GetClassAlignmentRecursive(). Otherwise returns the immediately available size.
[[nodiscard]]
std::optional<int> GetAlignmentOfTypeRecursive(std::map<sdk::TypeIdentifier, std::optional<int>>& cache, const CSchemaType& type) {
if (const auto* class_ = type.GetAsDeclaredClass(); class_ != nullptr) {
if (const auto* class_ = type.GetAsDeclaredClass(); class_ != nullptr && class_->m_pClassInfo != nullptr) {
return GetClassAlignmentRecursive(cache, *class_->m_pClassInfo);
} else {
return type.GetSizeAndAlignment().and_then([](const auto& e) { return std::get<1>(e); });
Expand Down

0 comments on commit 9257deb

Please sign in to comment.