Skip to content

Commit eabeea3

Browse files
committed
Fixed critical ResourceManager asset loading issue
- **ResourceManager**: Fixed double ownership issue causing silent texture failures - Add texture validation with isTextureValid() method - Implement cache validation to detect and recover from invalid cached textures - Add clearCache() method for state resets without destroying textures - Enhanced error logging throughout loading pipeline - Fix Release build texture validation to prevent cache invalidation - **Entity**: Fixed texture ownership model to prevent double destruction - Add dual texture support (owned SharedSDLTexture vs non-owned raw pointer) - Update constructors to handle ResourceManager-owned textures safely - Prevent premature texture destruction when ResourceManager caches textures - **Tests**: Added AssetLoadingTest suite for CI/CD validation - Test all game image assets with validation and caching verification - Test font loading across all game font sizes with text texture creation - Test UI text generation for all in-game text elements and colors - Test ResourceManager caching behavior and edge cases - Add smart working directory detection for CTest compatibility - 6 test cases covering complete asset loading pipeline - **CI/CD**: Added Release build testing to GitHub Actions workflow - Test both Debug and Release configurations - Ensure asset loading works correctly in optimized builds - **MenuSystem**: Changed end screen escape behavior (GoToMainMenu → QuitGame) - **Cleanup**: Remove old_game_loop.md and added TEST_RUNNERS.md file Fixes game-breaking asset loading failures that occurred after first gameplay session, where textures would fail to load silently and worsen with retries.
1 parent 8014bed commit eabeea3

File tree

10 files changed

+448
-321
lines changed

10 files changed

+448
-321
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ jobs:
7575
Write-Host "No compilation database found, skipping clang-tidy"
7676
}
7777
78-
- name: Build and Test via Script
78+
- name: Build and Test (Debug)
7979
shell: pwsh
8080
run: |
8181
# Run the test script which handles build, test execution, and CTest
8282
./test.ps1
83+
84+
- name: Build and Test (Release)
85+
shell: pwsh
86+
run: |
87+
# Test Release build as well
88+
cmake --build build --config Release
89+
./build/bin/Release/meowstro_tests.exe
8390
8491
- name: Upload Executable Artifact (main branch only)
8592
if: github.ref == 'refs/heads/main'
@@ -148,11 +155,17 @@ jobs:
148155
echo "No compilation database found, skipping clang-tidy"
149156
fi
150157
151-
- name: Build and Test via Script
158+
- name: Build and Test (Debug)
152159
run: |
153160
# Make script executable and run it
154161
chmod +x ./test.sh
155162
./test.sh
163+
164+
- name: Build and Test (Release)
165+
run: |
166+
# Test Release build as well
167+
cmake --build build --config Release
168+
./build/bin/meowstro_tests
156169
157170
- name: Upload Executable Artifact (main branch only)
158171
if: github.ref == 'refs/heads/main'
@@ -219,11 +232,17 @@ jobs:
219232
echo "No compilation database found, skipping clang-tidy"
220233
fi
221234
222-
- name: Build and Test via Script
235+
- name: Build and Test (Debug)
223236
run: |
224237
# Make script executable and run it
225238
chmod +x ./test.sh
226239
./test.sh
240+
241+
- name: Build and Test (Release)
242+
run: |
243+
# Test Release build as well
244+
cmake --build build --config Release
245+
./build/bin/meowstro_tests
227246
228247
- name: Upload Executable Artifact (main branch only)
229248
if: github.ref == 'refs/heads/main'

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ add_executable(meowstro_tests
216216
tests/unit/test_Sprite.cpp
217217
tests/unit/test_ResourceManager.cpp
218218
tests/unit/test_InputHandler.cpp
219+
tests/unit/test_AssetLoading.cpp
219220
)
220221

221222
target_link_libraries(meowstro_tests

TEST_RUNNERS.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,9 @@ test.bat
2929
4. **Display colored status** (✅ pass / ❌ fail)
3030
5. **Exit with proper codes** for CI integration
3131

32-
## Manual Commands
33-
34-
If you prefer to run commands manually:
35-
36-
```bash
37-
# Build everything
38-
cmake --build build --config Debug
39-
40-
# Run tests directly (detailed output)
41-
./build/bin/Debug/meowstro_tests.exe
42-
43-
# Run tests with CTest (CI-style)
44-
cd build && ctest --output-on-failure -C Debug
45-
46-
# Run specific test patterns
47-
./build/bin/Debug/meowstro_tests.exe --gtest_filter="GameStatsTest.*"
48-
```
49-
5032
## Adding New Tests
5133

52-
1. Create new test files in `tests/unit/`, `tests/component/`, etc.
34+
1. Create new test files in appropriate directory.
5335
2. Add the test file to `CMakeLists.txt` in the `meowstro_tests` target
5436
3. Rebuild and run tests
5537

include/Entity.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Entity
2222
// Get raw texture pointer for SDL API calls
2323
inline SDL_Texture* getTexture() const
2424
{
25-
return texture_ ? texture_->get() : nullptr;
25+
// Return shared texture if available, otherwise raw texture
26+
return texture_ ? texture_->get() : rawTexture_;
2627
}
2728
// Get shared texture for ownership transfer
2829
inline SharedSDLTexture getSharedTexture() const
@@ -37,10 +38,11 @@ class Entity
3738
{
3839
texture_ = texture;
3940
}
40-
// Set texture from raw pointer (creates shared ownership)
41+
// Set texture from raw pointer (non-owning reference)
4142
inline void setTexture(SDL_Texture* texture)
4243
{
43-
texture_ = texture ? makeSharedSDLTexture(texture) : nullptr;
44+
rawTexture_ = texture;
45+
texture_ = nullptr; // Clear shared texture
4446
}
4547
protected:
4648
// Fixed type consistency - use float to match member variables
@@ -55,5 +57,6 @@ class Entity
5557
float x;
5658
float y;
5759
SDL_Rect currentFrame;
58-
SharedSDLTexture texture_;
60+
SharedSDLTexture texture_; // For owned textures
61+
SDL_Texture* rawTexture_; // For non-owned textures (ResourceManager-owned)
5962
};

include/ResourceManager.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class ResourceManager {
2222
// Manual cleanup (called automatically in destructor)
2323
void cleanup();
2424

25+
// Clear texture cache without destroying textures (for state resets)
26+
void clearCache();
27+
28+
// Validate that a texture pointer is still valid
29+
bool isTextureValid(SDL_Texture* texture) const;
30+
2531
// Validity checking
2632
bool isValid() const { return m_valid; }
2733

0 commit comments

Comments
 (0)