Refactor/0328#1
Conversation
… management, and improve context handling
…ine buffer management, and enhance kernel launch parameters
…r handling, and enhance boundary face processing
…undary handling, and improve outflow clamping logic
…p and cuda::std::min/max for improved readability and consistency
…rocessor flag for improved preprocessor handling
…streamline export functions, and enhance field export handling
…boundary handling, and enhance return logic for outflow conditions
…readability and handling of edge cases for radius checks
…ocity boundary type, and optimize memory management for colliders
… error message for migration, refactor stable-fluids-3d.h to streamline boundary and field structures, and enhance main.cu with improved kernel functions and simulation parameters
…or message for migration, and refactor main.cpp to streamline snapshot handling and visualization logic
…sity scale and color presets, and remove unused camera input collection
…ability, and remove unused functions in the CUDA backend
…ssociated kernel, streamline device buffer management, and enhance memory handling for context destruction
…ove unused render modes, and enhance data handling in app.cpp and app.ixx
…ance snapshot handling, and improve memory management for velocity data
… field handling, and improve visualization settings management
…agement, enhance field handling, and improve capture storage logic
…amline visualization parameters, and improve data handling for velocity rendering
…ce arrow visualization parameters, and improve data handling for velocity rendering
…gs, enhance visualization parameters, and improve rendering logic for cloud simulation
…ty, enhance UI for scene and field selection, and improve data handling for visualization rendering
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3bd28e34a7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| switch (desc->kind) { | ||
| case STABLE_FLUIDS_EXPORT_FIELD: | ||
| { | ||
| const auto* field = &storage.fields[static_cast<std::size_t>(desc->field - 1u)]; |
There was a problem hiding this comment.
Validate field handle before indexing field storage
stable_fluids_export_cuda indexes storage.fields using desc->field - 1 without checking the handle range first. If desc->field is 0 or greater than the number of created fields (for example, a stale/uninitialized handle), this underflows/out-of-bounds and can crash or corrupt memory instead of returning an error.
Useful? React with 👍 / 👎.
| *out_context = nullptr; | ||
| if (desc == nullptr) return stable_fluids::invalid_argument; | ||
| if (desc->config.nx <= 0 || desc->config.ny <= 0 || desc->config.nz <= 0) return stable_fluids::invalid_config; | ||
| if (desc->config.cell_size <= 0.0f) return stable_fluids::invalid_config; | ||
| if (desc->config.dt <= 0.0f) return stable_fluids::invalid_config; | ||
| if (desc->config.diffuse_iterations <= 0 || desc->config.pressure_iterations <= 0) return stable_fluids::invalid_config; | ||
| const auto validate_boundary_face = [](const StableFluidsBoundaryFaceDesc& face) { | ||
| return face.type <= STABLE_FLUIDS_VELOCITY_BOUNDARY_OUTFLOW; | ||
| }; | ||
| const std::array boundary_faces{ | ||
| desc->config.domain_boundary.x_min, | ||
| desc->config.domain_boundary.x_max, | ||
| desc->config.domain_boundary.y_min, | ||
| desc->config.domain_boundary.y_max, | ||
| desc->config.domain_boundary.z_min, | ||
| desc->config.domain_boundary.z_max, | ||
| }; | ||
| for (const auto& boundary_face : boundary_faces) { | ||
| if (!validate_boundary_face(boundary_face)) return stable_fluids::invalid_config; | ||
| } | ||
| if (desc->field_count > 0 && desc->fields == nullptr) return stable_fluids::invalid_argument; | ||
| if (desc->field_count > 0 && (out_field_handles == nullptr || out_field_handle_capacity < desc->field_count)) return stable_fluids::invalid_argument; | ||
| if (desc->buoyancy_term_count > 0 && desc->buoyancy_terms == nullptr) return stable_fluids::invalid_argument; | ||
| for (uint32_t index = 0; index < desc->field_count; ++index) { | ||
| const auto& field = desc->fields[index]; | ||
| if (field.component_count == 0 || field.component_count > 4) return stable_fluids::invalid_field; | ||
| if ((field.flags & ~(STABLE_FLUIDS_FIELD_ADVECT | STABLE_FLUIDS_FIELD_DIFFUSE)) != 0u) return stable_fluids::invalid_field; | ||
| if (field.extension_mode > STABLE_FLUIDS_FIELD_EXTENSION_EXTRAPOLATE) return stable_fluids::invalid_field; | ||
| if (field.diffusion < 0.0f) return stable_fluids::invalid_field; | ||
| } | ||
| for (uint32_t index = 0; index < desc->buoyancy_term_count; ++index) { | ||
| const auto& term = desc->buoyancy_terms[index]; | ||
| if (term.field_index >= desc->field_count) return stable_fluids::invalid_field; | ||
| } | ||
|
|
||
| std::unique_ptr<StableFluidsContext_t> context{new (std::nothrow) StableFluidsContext_t{}}; | ||
| if (!context) return stable_fluids::out_of_memory; | ||
| context->config = desc->config; |
There was a problem hiding this comment.
Guard context-create pointers before dereferencing
stable_fluids_create_context_cuda dereferences both out_context and desc immediately, so passing a null pointer for either argument causes an immediate host-side crash. This makes the public C API fail hard on invalid inputs rather than returning a StableFluidsResult error.
Useful? React with 👍 / 👎.
@codex review