Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 1b7be3e

Browse files
committed
Fix some bitmaps being loaded directly, skipping alternative extension logic and causing crashes when extensions mismatch (followup to 022510c)
Add flag to not store in static map to ContentFile::GetAsBitmap Changed ContentFile::LoadAndReleaseBitmap and ContentFile::LoadAndReleaseSample to access specifier to private
1 parent 8615bb1 commit 1b7be3e

File tree

9 files changed

+39
-35
lines changed

9 files changed

+39
-35
lines changed

Activities/MultiplayerServerLobby.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ namespace RTE {
342342
m_pScenePreviewBitmap = create_bitmap_ex(8, Scene::PREVIEW_WIDTH, Scene::PREVIEW_HEIGHT);
343343

344344
ContentFile defaultPreview("Base.rte/GUIs/DefaultPreview.png");
345-
m_pDefaultPreviewBitmap = defaultPreview.LoadAndReleaseBitmap();
345+
m_pDefaultPreviewBitmap = defaultPreview.GetAsBitmap(COLORCONV_NONE, false);
346346

347347
clear_to_color(m_pScenePreviewBitmap, g_MaskColor);
348348

Entities/Scene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ int Scene::ReadProperty(std::string propName, Reader &reader)
13091309
else if (propName == "PreviewBitmapFile")
13101310
{
13111311
reader >> m_PreviewBitmapFile;
1312-
m_pPreviewBitmap = m_PreviewBitmapFile.LoadAndReleaseBitmap();
1312+
m_pPreviewBitmap = m_PreviewBitmapFile.GetAsBitmap(COLORCONV_NONE, false);
13131313
}
13141314
else if (propName == "Terrain")
13151315
{

Entities/SceneLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int SceneLayer::LoadData()
224224
blit(pCopyFrom, m_pMainBitmap, 0, 0, 0, 0, pCopyFrom->w, pCopyFrom->h);
225225
*/
226226
// Re-load directly from disk each time; don't do any caching of these bitmaps
227-
m_pMainBitmap = m_BitmapFile.LoadAndReleaseBitmap();
227+
m_pMainBitmap = m_BitmapFile.GetAsBitmap(COLORCONV_NONE, false);
228228

229229
m_MainBitmapOwned = true;
230230

Main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,21 @@ bool PlayIntroTitle() {
339339
// Load the Intro slides
340340
BITMAP **apIntroSlides = new BITMAP *[SLIDECOUNT];
341341
ContentFile introSlideFile("Base.rte/GUIs/Title/Intro/IntroSlideA.png");
342-
apIntroSlides[SLIDEPAST] = introSlideFile.LoadAndReleaseBitmap();
342+
apIntroSlides[SLIDEPAST] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
343343
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideB.png");
344-
apIntroSlides[SLIDENOW] = introSlideFile.LoadAndReleaseBitmap();
344+
apIntroSlides[SLIDENOW] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
345345
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideC.png");
346-
apIntroSlides[SLIDEVR] = introSlideFile.LoadAndReleaseBitmap();
346+
apIntroSlides[SLIDEVR] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
347347
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideD.png");
348-
apIntroSlides[SLIDETRAVEL] = introSlideFile.LoadAndReleaseBitmap();
348+
apIntroSlides[SLIDETRAVEL] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
349349
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideE.png");
350-
apIntroSlides[SLIDEALIENS] = introSlideFile.LoadAndReleaseBitmap();
350+
apIntroSlides[SLIDEALIENS] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
351351
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideF.png");
352-
apIntroSlides[SLIDETRADE] = introSlideFile.LoadAndReleaseBitmap();
352+
apIntroSlides[SLIDETRADE] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
353353
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideG.png");
354-
apIntroSlides[SLIDEPEACE] = introSlideFile.LoadAndReleaseBitmap();
354+
apIntroSlides[SLIDEPEACE] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
355355
introSlideFile.SetDataPath("Base.rte/GUIs/Title/Intro/IntroSlideH.png");
356-
apIntroSlides[SLIDEFRONTIER] = introSlideFile.LoadAndReleaseBitmap();
356+
apIntroSlides[SLIDEFRONTIER] = introSlideFile.GetAsBitmap(COLORCONV_NONE, false);
357357

358358
ContentFile alphaFile;
359359
BITMAP *pAlpha = 0;

Managers/FrameMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace RTE {
266266
CreateBackBuffers();
267267

268268
ContentFile scenePreviewGradientFile("Base.rte/GUIs/PreviewSkyGradient.png");
269-
m_ScenePreviewDumpGradient = scenePreviewGradientFile.LoadAndReleaseBitmap(COLORCONV_8_TO_32);
269+
m_ScenePreviewDumpGradient = scenePreviewGradientFile.GetAsBitmap(COLORCONV_8_TO_32, false);
270270

271271
return 0;
272272
}

Managers/SceneMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ bool SceneMan::LoadUnseenLayer(std::string bitmapPath, int team)
14091409
{
14101410
ContentFile bitmapFile(bitmapPath.c_str());
14111411
SceneLayer *pUnseenLayer = new SceneLayer();
1412-
if (pUnseenLayer->Create(bitmapFile.LoadAndReleaseBitmap(), true, Vector(), m_pCurrentScene->WrapsX(), m_pCurrentScene->WrapsY(), Vector(1.0, 1.0)) < 0)
1412+
if (pUnseenLayer->Create(bitmapFile.GetAsBitmap(COLORCONV_NONE, false), true, Vector(), m_pCurrentScene->WrapsX(), m_pCurrentScene->WrapsY(), Vector(1.0, 1.0)) < 0)
14131413
{
14141414
g_ConsoleMan.PrintString("ERROR: Loading background layer " + pUnseenLayer->GetPresetName() + "\'s data failed!");
14151415
return false;

Menus/ScenarioGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int ScenarioGUI::Create(Controller *pController)
317317

318318
// Load default preview bitmap
319319
ContentFile defaultPreview("Base.rte/GUIs/DefaultPreview.png");
320-
m_pDefaultPreviewBitmap = defaultPreview.LoadAndReleaseBitmap();
320+
m_pDefaultPreviewBitmap = defaultPreview.GetAsBitmap(COLORCONV_NONE, false);
321321

322322
clear_to_color(m_pScenePreviewBitmap, g_MaskColor);
323323

System/ContentFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace RTE {
103103

104104
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105105

106-
BITMAP * ContentFile::GetAsBitmap(int conversionMode, const std::string &dataPathToSpecificFrame) {
106+
BITMAP * ContentFile::GetAsBitmap(int conversionMode, bool storeBitmap, const std::string &dataPathToSpecificFrame) {
107107
if (m_DataPath.empty()) {
108108
return nullptr;
109109
}
@@ -132,7 +132,7 @@ namespace RTE {
132132
returnBitmap = LoadAndReleaseBitmap(conversionMode, dataPathToLoad); // NOTE: This takes ownership of the bitmap file
133133

134134
// Insert the bitmap into the map, PASSING OVER OWNERSHIP OF THE LOADED DATAFILE
135-
s_LoadedBitmaps.at(bitDepth).insert(std::pair<std::string, BITMAP *>(dataPathToLoad, returnBitmap));
135+
if (storeBitmap) { s_LoadedBitmaps.at(bitDepth).insert({ dataPathToLoad, returnBitmap }); }
136136
}
137137
return returnBitmap;
138138
}
@@ -166,7 +166,7 @@ namespace RTE {
166166
char framePath[1024];
167167
for (int frameNum = 0; frameNum < frameCount; frameNum++) {
168168
std::snprintf(framePath, sizeof(framePath), "%s%03i%s", m_DataPathWithoutExtension.c_str(), frameNum, m_DataPathExtension.c_str());
169-
returnBitmaps[frameNum] = GetAsBitmap(conversionMode, framePath);
169+
returnBitmaps[frameNum] = GetAsBitmap(conversionMode, true, framePath);
170170
}
171171
return returnBitmaps;
172172
}
@@ -208,7 +208,7 @@ namespace RTE {
208208
returnSample = LoadAndReleaseSample(abortGameForInvalidSound, asyncLoading); //NOTE: This takes ownership of the sample file
209209

210210
// Insert the Sound object into the map, PASSING OVER OWNERSHIP OF THE LOADED FILE
211-
s_LoadedSamples.insert(std::pair<std::string, FMOD::Sound *>(m_DataPath, returnSample));
211+
s_LoadedSamples.insert({ m_DataPath, returnSample });
212212
}
213213
return returnSample;
214214
}

System/ContentFile.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ namespace RTE {
119119
/// Gets the data represented by this ContentFile object as an Allegro BITMAP, loading it into the static maps if it's not already loaded. Note that ownership of the BITMAP is NOT transferred!
120120
/// </summary>
121121
/// <param name="conversionMode">The Allegro color conversion mode to use when loading this bitmap.</param>
122+
/// <param name="storeBitmap">Whether to store the BITMAP in the relevant static map after loading it or not.</param>
122123
/// <param name="dataPathToSpecificFrame">Path to a specific frame when loading an animation to avoid overwriting the original preset DataPath when loading each frame.</param>
123124
/// <returns>Pointer to the BITMAP loaded from disk.</returns>
124-
BITMAP * GetAsBitmap(int conversionMode = 0, const std::string &dataPathToSpecificFrame = "");
125+
BITMAP * GetAsBitmap(int conversionMode = 0, bool storeBitmap = true, const std::string &dataPathToSpecificFrame = "");
125126

126127
/// <summary>
127128
/// Gets the data represented by this ContentFile object as an array of Allegro BITMAPs, each representing a frame in the animation.
@@ -132,15 +133,6 @@ namespace RTE {
132133
/// <returns>Pointer to the beginning of the array of BITMAP pointers loaded from the disk, the length of which is specified with the FrameCount argument.</returns>
133134
BITMAP ** GetAsAnimation(int frameCount = 1, int conversionMode = 0);
134135

135-
/// <summary>
136-
/// Loads and transfers the data represented by this ContentFile object as an Allegro BITMAP. Ownership of the BITMAP IS transferred!
137-
/// Note that this is relatively slow since it reads the data from disk each time.
138-
/// </summary>
139-
/// <param name="conversionMode">The Allegro color conversion mode to use when loading this bitmap. Only applies the first time a bitmap is loaded from the disk.</param>
140-
/// <param name="dataPathToSpecificFrame">Path to a specific frame when loading an animation to avoid overwriting the original preset DataPath when loading each frame.</param>
141-
/// <returns>Pointer to the BITMAP loaded from disk.</returns>
142-
BITMAP * LoadAndReleaseBitmap(int conversionMode = 0, const std::string &dataPathToSpecificFrame = "");
143-
144136
/// <summary>
145137
/// Gets the data represented by this ContentFile object as an FMOD FSOUND_SAMPLE, loading it into the static maps if it's not already loaded. Ownership of the FSOUND_SAMPLE is NOT transferred!
146138
/// </summary>
@@ -149,13 +141,6 @@ namespace RTE {
149141
/// <returns>Pointer to the FSOUND_SAMPLE loaded from disk.</returns>
150142
FMOD::Sound * GetAsSample(bool abortGameForInvalidSound = true, bool asyncLoading = true);
151143

152-
/// <summary>
153-
/// Loads and transfers the data represented by this ContentFile object as an FMOD FSOUND_SAMPLE. Ownership of the FSOUND_SAMPLE is NOT transferred!
154-
/// </summary>
155-
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error. Default true.</param>
156-
/// <param name="asyncLoading">Whether to enable FMOD asynchronous loading or not. Should be disabled for loading audio files with Lua AddSound.
157-
/// <returns>Pointer to the FSOUND_SAMPLE loaded from disk.</returns>
158-
FMOD::Sound * LoadAndReleaseSample(bool abortGameForInvalidSound = true, bool asyncLoading = true);
159144
#pragma endregion
160145

161146
#pragma region Class Info
@@ -190,6 +175,25 @@ namespace RTE {
190175

191176
private:
192177

178+
#pragma region Data Handling
179+
/// <summary>
180+
/// Loads and transfers the data represented by this ContentFile object as an Allegro BITMAP. Ownership of the BITMAP IS transferred!
181+
/// Note that this is relatively slow since it reads the data from disk each time.
182+
/// </summary>
183+
/// <param name="conversionMode">The Allegro color conversion mode to use when loading this bitmap. Only applies the first time a bitmap is loaded from the disk.</param>
184+
/// <param name="dataPathToSpecificFrame">Path to a specific frame when loading an animation to avoid overwriting the original preset DataPath when loading each frame.</param>
185+
/// <returns>Pointer to the BITMAP loaded from disk.</returns>
186+
BITMAP * LoadAndReleaseBitmap(int conversionMode = 0, const std::string &dataPathToSpecificFrame = "");
187+
188+
/// <summary>
189+
/// Loads and transfers the data represented by this ContentFile object as an FMOD FSOUND_SAMPLE. Ownership of the FSOUND_SAMPLE is NOT transferred!
190+
/// </summary>
191+
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error. Default true.</param>
192+
/// <param name="asyncLoading">Whether to enable FMOD asynchronous loading or not. Should be disabled for loading audio files with Lua AddSound.
193+
/// <returns>Pointer to the FSOUND_SAMPLE loaded from disk.</returns>
194+
FMOD::Sound * LoadAndReleaseSample(bool abortGameForInvalidSound = true, bool asyncLoading = true);
195+
#pragma endregion
196+
193197
/// <summary>
194198
/// Clears all the member variables of this ContentFile, effectively resetting the members of this abstraction level only.
195199
/// </summary>

0 commit comments

Comments
 (0)