codemap generation
Some checks failed
Some checks failed
This commit is contained in:
@@ -208,6 +208,89 @@ func load_scene(path: String) -> void:
|
||||
get_tree().change_scene_to_packed(packed_scene)
|
||||
```
|
||||
|
||||
### Memory Management Standards
|
||||
|
||||
**Critical Rules**:
|
||||
1. **Always use `queue_free()`** instead of `free()` for node cleanup
|
||||
2. **Wait for frame completion** after queueing nodes for removal
|
||||
3. **Clear references before cleanup** to prevent access to freed memory
|
||||
4. **Connect signals properly** for dynamically created nodes
|
||||
|
||||
```gdscript
|
||||
# ✅ Correct memory management
|
||||
for child in children_to_remove:
|
||||
child.queue_free()
|
||||
await get_tree().process_frame # Wait for cleanup
|
||||
|
||||
# ❌ Dangerous pattern (causes crashes)
|
||||
for child in children_to_remove:
|
||||
child.free() # Immediate deletion can crash
|
||||
```
|
||||
|
||||
**Why This Matters**: Using `free()` causes immediate deletion which can crash if the node is still referenced elsewhere. `queue_free()` waits until it's safe to delete.
|
||||
|
||||
**See Also**: [ARCHITECTURE.md](ARCHITECTURE.md#memory-management-queue_free-over-free) for architectural rationale.
|
||||
|
||||
### Input Validation Standards
|
||||
|
||||
All user inputs must be validated before processing.
|
||||
|
||||
**Validation Requirements**:
|
||||
1. **Type checking**: Verify input types before processing
|
||||
2. **Bounds checking**: Validate numeric ranges and array indices
|
||||
3. **Null checking**: Handle null and empty inputs gracefully
|
||||
4. **Whitelist validation**: Validate against known good values
|
||||
|
||||
```gdscript
|
||||
# ✅ Proper input validation
|
||||
func set_volume(value: float, setting_key: String) -> bool:
|
||||
# Whitelist validation
|
||||
if not setting_key in ["master_volume", "music_volume", "sfx_volume"]:
|
||||
DebugManager.log_error("Invalid volume setting key: " + str(setting_key), "Settings")
|
||||
return false
|
||||
|
||||
# Bounds checking
|
||||
var clamped_value = clamp(value, 0.0, 1.0)
|
||||
if clamped_value != value:
|
||||
DebugManager.log_warn("Volume value clamped from %f to %f" % [value, clamped_value], "Settings")
|
||||
|
||||
SettingsManager.set_setting(setting_key, clamped_value)
|
||||
return true
|
||||
|
||||
# ✅ Grid movement validation
|
||||
func _move_cursor(direction: Vector2i) -> void:
|
||||
# Bounds checking
|
||||
if abs(direction.x) > 1 or abs(direction.y) > 1:
|
||||
DebugManager.log_error("Invalid cursor direction: " + str(direction), "Match3")
|
||||
return
|
||||
|
||||
# Null/empty checking
|
||||
if not grid or grid.is_empty():
|
||||
DebugManager.log_error("Grid not initialized", "Match3")
|
||||
return
|
||||
|
||||
# Process validated input
|
||||
var new_pos = cursor_pos + direction
|
||||
# ... continue with validated data
|
||||
```
|
||||
|
||||
**See Also**: [ARCHITECTURE.md](ARCHITECTURE.md#input-validation-whitelist-approach) for architectural decision rationale.
|
||||
|
||||
## Code Quality Checklist
|
||||
|
||||
Before committing code, verify:
|
||||
|
||||
- [ ] All user inputs validated (type, bounds, null checks)
|
||||
- [ ] Error handling with fallback mechanisms implemented
|
||||
- [ ] Memory cleanup uses `queue_free()` not `free()`
|
||||
- [ ] No global static state introduced
|
||||
- [ ] Proper logging with categories and appropriate levels
|
||||
- [ ] Race condition protection for async operations
|
||||
- [ ] Input actions defined in project input map
|
||||
- [ ] Resources loaded with null/type checking
|
||||
- [ ] Documentation updated for new public APIs
|
||||
- [ ] Test coverage for new functionality
|
||||
|
||||
## Git Workflow
|
||||
|
||||
### Commit Guidelines
|
||||
|
||||
Reference in New Issue
Block a user