Files
vibe3_physics/source/shapes_mgr/shape_manager.cpp
Sergio Valor 0fe2efc051 Fix: Resolver crash de nullptr en Engine::initialize() y documentar facade pattern
PROBLEMA CRÍTICO RESUELTO:
- El programa compilaba pero crasheaba inmediatamente al ejecutar
- Stack trace apuntaba a UIManager::updatePhysicalWindowSize() (línea 135)
- Root cause: Engine::initialize() llamaba updatePhysicalWindowSize() en línea 228
  ANTES de crear ui_manager_ en línea 232 → nullptr dereference

SOLUCIÓN:
- Calcular tamaño físico de ventana inline sin llamar al método completo
- Usar SDL_GetWindowSizeInPixels() directamente antes de crear ui_manager_
- Pasar valores calculados a UIManager::initialize()

CAMBIOS ADICIONALES:
1. engine.h: Documentar duplicación pragmática Engine ↔ StateManager
   - Variables de estado DEMO/LOGO mantenidas temporalmente en Engine
   - StateManager mantiene current_app_mode_ (fuente de verdad)
   - Comentarios explicativos para futuras migraciones

2. shape_manager.cpp: Documentar facade pattern completo
   - Añadidos comentarios extensivos explicando stubs
   - Cada método stub documenta por qué Engine mantiene implementación
   - Clarifica dependencias (SceneManager, UIManager, notificaciones)

RESULTADO:
 Compilación exitosa (sin errores)
 Aplicación ejecuta sin crashes
 Inicialización de UIManager correcta
 Todos los recursos cargan apropiadamente

Archivos modificados:
- source/engine.cpp: Fix de inicialización (líneas 227-238)
- source/engine.h: Documentación de estado duplicado
- source/shapes_mgr/shape_manager.cpp: Documentación facade

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 16:54:23 +02:00

82 lines
3.0 KiB
C++

#include "shape_manager.h"
#include <algorithm> // for std::min, std::max
#include <cstdlib> // for rand
#include "../defines.h" // for constantes
#include "../engine.h" // for Engine (callbacks)
ShapeManager::ShapeManager()
: engine_(nullptr)
, current_mode_(SimulationMode::PHYSICS)
, current_shape_type_(ShapeType::SPHERE)
, last_shape_type_(ShapeType::SPHERE)
, active_shape_(nullptr)
, shape_scale_factor_(1.0f)
, depth_zoom_enabled_(true) {
}
ShapeManager::~ShapeManager() {
}
void ShapeManager::initialize(Engine* engine) {
engine_ = engine;
}
// ============================================================================
// IMPLEMENTACIONES FACADE - Engine mantiene lógica compleja temporalmente
// ============================================================================
// Nota: Los métodos delegables sin dependencias complejas están implementados.
// Los métodos con dependencias fuertes (SceneManager, tema, notificaciones)
// se mantienen como stubs - Engine los llama directamente.
// ============================================================================
void ShapeManager::toggleShapeMode(bool force_gravity_on_exit) {
// STUB: Engine mantiene implementación completa en toggleShapeModeInternal()
// Razón: Requiere acceso a SceneManager, UIManager, StateManager
}
void ShapeManager::activateShape(ShapeType type) {
// STUB: Engine mantiene implementación completa en activateShapeInternal()
// Razón: Requiere acceso a SceneManager (desactivar gravedad, atracción)
}
void ShapeManager::handleShapeScaleChange(bool increase) {
// STUB: Engine gestiona esto directamente
// Razón: Requiere mostrar notificación (UIManager)
}
void ShapeManager::resetShapeScale() {
// STUB: Engine gestiona esto directamente
// Razón: Requiere mostrar notificación (UIManager)
}
void ShapeManager::toggleDepthZoom() {
depth_zoom_enabled_ = !depth_zoom_enabled_;
}
void ShapeManager::update(float delta_time) {
// STUB: Engine mantiene implementación completa en updateShape()
// Razón: Requiere acceso a SceneManager (bolas), aplicar física de atracción
}
void ShapeManager::generateShape() {
// Implementación delegable: Solo llama a Shape::generatePoints()
if (!active_shape_) return;
// NOTA: Requiere parámetros de Engine (num_points, screen_width, screen_height)
// Por ahora es stub - Engine lo llama directamente con parámetros
}
void ShapeManager::activateShapeInternal(ShapeType type) {
// STUB: Engine mantiene implementación completa
// Razón: Crea instancias polimórficas de Shape (requiere includes de todas las shapes)
}
void ShapeManager::clampShapeScale() {
// Implementación simple: Limitar scale_factor_ entre MIN y MAX
// NOTA: Cálculo completo requiere current_screen_width/height de Engine
// Por ahora simplemente limita al rango base
shape_scale_factor_ = std::max(SHAPE_SCALE_MIN, std::min(SHAPE_SCALE_MAX, shape_scale_factor_));
}