fix(catia): cap FBB tail-recursion to prevent stack overflow
This commit is contained in:
@@ -128,8 +128,9 @@ bool parse_vertices(const std::vector<std::uint8_t>& d,
|
||||
|
||||
} // namespace
|
||||
|
||||
bool extract_catia_fbb_mesh(const std::vector<std::uint8_t>& main,
|
||||
std::vector<BrepModel>& bodies, std::string& error) {
|
||||
static bool extract_catia_fbb_mesh_impl(
|
||||
const std::vector<std::uint8_t>& main, std::vector<BrepModel>& bodies,
|
||||
std::string& error, std::size_t depth) {
|
||||
// 1) 找最大连续 FBB run(stride 8)。
|
||||
std::size_t fbb_start = 0;
|
||||
std::size_t fbb_count = 0;
|
||||
@@ -204,12 +205,12 @@ bool extract_catia_fbb_mesh(const std::vector<std::uint8_t>& main,
|
||||
}
|
||||
if (packets.empty()) {
|
||||
// 最大 run 失败时,尝试后续 run(递归裁剪,避免多 population 误选)。
|
||||
if (fbb_start + 8 < main.size()) {
|
||||
if (depth < 64 && fbb_start + 8 < main.size()) {
|
||||
std::vector<std::uint8_t> tail(main.begin() + fbb_start + 8,
|
||||
main.end());
|
||||
std::vector<BrepModel> alt;
|
||||
std::string alt_error;
|
||||
if (extract_catia_fbb_mesh(tail, alt, alt_error)) {
|
||||
if (extract_catia_fbb_mesh_impl(tail, alt, alt_error, depth + 1)) {
|
||||
for (auto& b : alt) bodies.push_back(std::move(b));
|
||||
error = alt_error;
|
||||
return true;
|
||||
@@ -270,4 +271,9 @@ bool extract_catia_fbb_mesh(const std::vector<std::uint8_t>& main,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extract_catia_fbb_mesh(const std::vector<std::uint8_t>& main,
|
||||
std::vector<BrepModel>& bodies, std::string& error) {
|
||||
return extract_catia_fbb_mesh_impl(main, bodies, error, 0);
|
||||
}
|
||||
|
||||
} // namespace vde::brep::native
|
||||
|
||||
Reference in New Issue
Block a user