Skip to content

Commit e3619ea

Browse files
authored
Merge pull request #220 from RobLoach/unload-protection
Add protection against attempting to Unload() multiple times
2 parents 76586c0 + 466510d commit e3619ea

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

include/Font.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ class Font : public ::Font {
101101
}
102102

103103
void Unload() {
104-
UnloadFont(*this);
104+
// Protect against calling UnloadFont() twice.
105+
if (baseSize != 0) {
106+
UnloadFont(*this);
107+
baseSize = 0;
108+
}
105109
}
106110

107111
GETTERSETTER(int, BaseSize, baseSize)

include/Sound.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ class Sound : public ::Sound {
9595
* Unload sound
9696
*/
9797
inline void Unload() {
98-
::UnloadSound(*this);
98+
// Protect against calling UnloadSound() twice.
99+
if (frameCount != 0) {
100+
::UnloadSound(*this);
101+
frameCount = 0;
102+
}
99103
}
100104

101105
/**

include/TextureUnmanaged.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ class TextureUnmanaged : public ::Texture {
132132
* Unload texture from GPU memory (VRAM)
133133
*/
134134
inline void Unload() {
135-
::UnloadTexture(*this);
135+
// Protect against calling UnloadTexture() twice.
136+
if (id != 0) {
137+
::UnloadTexture(*this);
138+
id = 0;
139+
}
136140
}
137141

138142
/**

include/Wave.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class Wave : public ::Wave {
161161
* Unload wave data
162162
*/
163163
void Unload() {
164+
// Protect against calling UnloadWave() twice.
164165
if (data != nullptr) {
165166
::UnloadWave(*this);
166167
data = nullptr;

0 commit comments

Comments
 (0)