Skip to content

Commit

Permalink
Fix wrong subdivision behavior in VoxelGeneratorGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Apr 10, 2024
1 parent 9257d62 commit f382d6c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Primarily developped with Godot 4.2.
- Fixed error when using more than 12 weight output nodes
- Fixed using a graph as brush wasn't working with some transforms
- Fixed wrapping error with the `Image` node in negative coordinates
- Fixed wrong behavior and crashes when generating chunks large enough to trigger the "subdivision" feature
- `VoxelInstanceLibraryMultimeshItem`: fixed error when using "Update From Scene" and trying to undo/redo it
- `VoxelTool`: fixed `paste` wrongly printing an error despite working fine
- `VoxelToolLodTerrain`:
Expand Down
3 changes: 2 additions & 1 deletion generators/graph/voxel_generator_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ VoxelGenerator::Result VoxelGeneratorGraph::generate_block(VoxelGenerator::Voxel
const int type_output_buffer_index = runtime_ptr->type_output_buffer_index;

FixedArray<unsigned int, pg::Runtime::MAX_OUTPUTS> required_outputs;
unsigned int required_outputs_count = 0;

bool all_sdf_is_air = (sdf_output_buffer_index != -1) && (type_output_buffer_index == -1);
bool all_sdf_is_matter = all_sdf_is_air;
Expand Down Expand Up @@ -505,6 +504,8 @@ VoxelGenerator::Result VoxelGeneratorGraph::generate_block(VoxelGenerator::Voxel
runtime.analyze_range(cache.state, range_inputs.get());
}

unsigned int required_outputs_count = 0;

bool sdf_is_air = true;
bool sdf_is_uniform = true;
if (sdf_output_buffer_index != -1) {
Expand Down
1 change: 1 addition & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void run_voxel_tests() {
VOXEL_TEST(test_voxel_graph_function_execute);
VOXEL_TEST(test_voxel_graph_image);
VOXEL_TEST(test_voxel_graph_many_weight_outputs);
VOXEL_TEST(test_voxel_graph_many_subdivisions);
VOXEL_TEST(test_island_finder);
VOXEL_TEST(test_unordered_remove_if);
VOXEL_TEST(test_instance_data_serialization);
Expand Down
30 changes: 30 additions & 0 deletions tests/voxel/test_voxel_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2084,4 +2084,34 @@ void test_image_range_grid() {
Interval(5 * image_height + image_height - 5, 5 * image_height + image_height + 20));
}

void test_voxel_graph_many_subdivisions() {
Ref<VoxelGeneratorGraph> generator;
generator.instantiate();
{
VoxelGraphFunction &g = **generator->get_main_function();

// FastNoise3D --- OutSDF

const uint32_t n_out_sdf = g.create_node(VoxelGraphFunction::NODE_OUTPUT_SDF, Vector2(0, 0));
const uint32_t n_noise = g.create_node(VoxelGraphFunction::NODE_FAST_NOISE_3D, Vector2());

Ref<ZN_FastNoiseLite> noise;
noise.instantiate();
g.set_node_param(n_noise, 0, noise);

g.add_connection(n_noise, 0, n_out_sdf, 0);

CompilationResult result = generator->compile(false);
ZN_TEST_ASSERT(result.success);
}

VoxelBuffer vb(VoxelBuffer::ALLOCATOR_DEFAULT);
vb.create(16, 512, 16);

// Just checking that it doesn't crash.
// There was an issue with subdivisions where we gathered "required outputs" filling a small array before running
// the graph, but it didn't reset that process at next subdivisions so eventually overran the array
generator->generate_block(VoxelGenerator::VoxelQueryData{ vb, Vector3i(0, 0, 0), 0 });
}

} // namespace zylann::voxel::tests
1 change: 1 addition & 0 deletions tests/voxel/test_voxel_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void test_voxel_graph_function_execute();
void test_voxel_graph_image();
void test_voxel_graph_many_weight_outputs();
void test_image_range_grid();
void test_voxel_graph_many_subdivisions();

} // namespace zylann::voxel::tests

Expand Down

0 comments on commit f382d6c

Please sign in to comment.