Compare commits

...

4 Commits

Author SHA1 Message Date
Maddie Busig
65f379930f Modify generate_axiom to use generate_group helper 2025-05-11 08:54:26 -07:00
Maddie Busig
7e8d4d6d1d Fix incorrect check for maximum marker/leaf capacity reached
Caused overflow and invalid read/writes
2025-05-11 08:50:54 -07:00
Maddie Busig
b0cc69848f Remove .gba files from gitignore 2025-05-11 08:50:24 -07:00
Maddie Busig
2df802d207 Fix missing catch for ETL exception 2025-05-11 08:49:54 -07:00
3 changed files with 18 additions and 24 deletions

1
.gitignore vendored
View File

@ -50,7 +50,6 @@ _deps
build/
build*
*.gba
*.elf
*.sav

View File

@ -226,34 +226,24 @@ void generator_t::clear_all_buffers() {
}
bool generator_t::generate_axiom(etl::ivector<marker_t>& out_markers) {
const group_output_t& axiom_output = m_group_outputs[m_axiom];
vec2 init_pos(0, 0);
mat<2, 2> init_orient = create_rotation(1, 0);
if (m_leafs_cur->capacity() < axiom_output.m_child_leafs.size() ||
m_wleafs_cur->capacity() < axiom_output.m_child_wleafs.size() ||
out_markers.capacity() < axiom_output.m_child_markers.size()) {
mlog::debug << "Reached limit" << endl;
return false;
}
for (const leaf_t& leaf : axiom_output.m_child_leafs) {
m_leafs_cur->push_back(leaf);
}
for (const weighted_leaf_t& wleaf : axiom_output.m_child_wleafs) {
m_wleafs_cur->push_back(wleaf);
}
for (const marker_t& mark : axiom_output.m_child_markers) {
out_markers.push_back(mark);
}
return true;
return generate_group(m_axiom, init_pos, init_orient, out_markers);
}
bool generator_t::generate_group(group_id_t gid, vec2 pos, mat<2, 2> orient, etl::ivector<marker_t>& out_markers) {
const group_output_t& group_output = m_group_outputs[gid];
if (m_leafs_cur->capacity() < group_output.m_child_leafs.size() ||
m_wleafs_cur->capacity() < group_output.m_child_wleafs.size() ||
out_markers.capacity() < group_output.m_child_markers.size()) {
size_t new_leafs_size = m_leafs_cur->size() + group_output.m_child_leafs.size();
size_t new_wleafs_size = m_wleafs_cur->size() + group_output.m_child_wleafs.size();
size_t new_marker_size = out_markers.size() + group_output.m_child_markers.size();
bool reached_max_leafs = m_leafs_cur->capacity() < new_leafs_size;
bool reached_max_wleafs = m_wleafs_cur->capacity() < new_wleafs_size;
bool reached_max_markers = out_markers.capacity() < new_marker_size;
if (reached_max_leafs || reached_max_wleafs || reached_max_markers) {
mlog::debug << "Reached limit" << endl;
return false;
}

View File

@ -80,6 +80,9 @@ int main(void) {
} catch (const mtl::exception&) {
mlog::info << "Failed to configure ruleset, caught exception" << endl;
return 0;
} catch (const etl::exception& e) {
mlog::error << "Failed to configure ruleset, caught ETL exception" << endl;
return 0;
}
size_t gen_num = 0;
@ -95,8 +98,10 @@ int main(void) {
}
} catch (etl::exception& e) {
mlog::error << "Caught ETL exception: " << e.what() << endl;
return 0;
} catch (mtl::exception& e) {
mlog::error << "Caught MTL exception: " << e.id() << endl;
return 0;
}
mlog::info << "Stepped " << gen.generation_num() << " generations" << mtl::endl;