Skip to content

Commit 953babd

Browse files
committed
Rework initialization to fix loading bitmaps from static map crash
1 parent ca91fc2 commit 953babd

File tree

7 files changed

+81
-50
lines changed

7 files changed

+81
-50
lines changed

Editor/GUIEditorApp.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,23 @@
1111

1212
#include "RTEError.h"
1313

14+
#include "TimerMan.h"
15+
16+
using namespace std;
17+
1418
namespace RTE {
1519

1620
volatile bool g_Quit;
1721
AllegroScreen *g_Screen;
1822
AllegroInput *g_Input;
19-
GUIEditorApp g_GUIEditor;
2023

2124
#define ROOTORIGINX 300
2225
#define ROOTORIGINY 120
2326

24-
2527
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2628

27-
/// <summary>
28-
/// Quit Handler for Allegro.
29-
/// </summary>
30-
void QuitHandler(void) { g_GUIEditor.OnQuitButton(); }
31-
32-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33-
34-
bool GUIEditorApp::Initialize(void) {
35-
allegro_init();
36-
install_keyboard();
29+
bool GUIEditorApp::Initialize() {
30+
install_keyboard();
3731

3832
int ResW = 1024;
3933
int ResH = 768;
@@ -45,17 +39,10 @@ bool GUIEditorApp::Initialize(void) {
4539

4640
set_color_depth(BPP);
4741
set_gfx_mode(GFX_AUTODETECT_WINDOWED, ResW, ResH, 0, 0);
48-
set_close_button_callback(QuitHandler);
4942
set_window_title("Cortex Command: GUI Editor");
5043

5144
set_color_conversion(COLORCONV_MOST);
5245

53-
// Just going to discard the bitmap, we're only interested in the palette
54-
BITMAP *tempBitmap;
55-
PALETTE newPalette;
56-
//if (!(tempBitmap = load_bitmap("Palette.bmp", NULL)))// newPalette)))
57-
// RTEAbort("Failed to load palette from bitmap with following path:\n\nBase.rte/palette.bmp");
58-
5946
PALETTE ccpal;
6047
get_palette(ccpal);
6148
create_trans_table(&m_LessTransTable, ccpal, 192, 192, 192, 0);
@@ -69,8 +56,10 @@ bool GUIEditorApp::Initialize(void) {
6956
g_Screen = new AllegroScreen(m_pBackBuffer32);
7057
g_Input = new AllegroInput(-1);
7158

59+
PALETTE newPalette;
60+
7261
// Set the current palette
73-
set_palette(newPalette);
62+
//set_palette(newPalette);
7463

7564
// Update what black is now with the loaded palette
7665
m_BlackColor = bestfit_color(newPalette, 0, 0, 0);
@@ -329,7 +318,6 @@ bool GUIEditorApp::Update(void)
329318

330319
m_pEditorManager->DrawMouse();
331320

332-
333321
blit(m_pBackBuffer32, screen, 0, 0, 0, 0, m_pBackBuffer32->w, m_pBackBuffer32->h);
334322

335323
return !g_Quit;

Editor/GUIEditorApp.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
#include "GUIPropertyPage.h"
99
#include "GUIListBox.h"
1010

11+
#include "Singleton.h"
12+
13+
#define g_GUIEditor GUIEditorApp::Instance()
14+
1115
namespace RTE {
1216

1317
/// <summary>
1418
/// GUI Editor Application class that handles the main editor app.
1519
/// </summary>
16-
class GUIEditorApp {
20+
class GUIEditorApp : public Singleton<GUIEditorApp> {
1721

1822
public:
1923

@@ -40,7 +44,7 @@ namespace RTE {
4044
/// <summary>
4145
/// Destructor method used to clean up a GUIEditorApp object.
4246
/// </summary>
43-
~GUIEditorApp() {}
47+
~GUIEditorApp() = default;
4448

4549
/// <summary>
4650
/// Initializes the editor app.
@@ -178,7 +182,10 @@ namespace RTE {
178182
bool m_bDirty;
179183
bool m_bSnapGrid;
180184
int m_nGridSize;
185+
186+
// Disallow the use of some implicit methods.
187+
GUIEditorApp(const GUIEditorApp &reference) = delete;
188+
GUIEditorApp &operator=(const GUIEditorApp &rhs) = delete;
181189
};
182-
extern GUIEditorApp g_GUIEditor;
183190
}
184191
#endif

GUIEditor.vcxproj

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,20 @@
7575
</DisableSpecificWarnings>
7676
<IntrinsicFunctions>false</IntrinsicFunctions>
7777
<OmitFramePointers>false</OmitFramePointers>
78-
<ConformanceMode>true</ConformanceMode>
78+
<ConformanceMode>false</ConformanceMode>
7979
<LanguageStandard>stdcpp17</LanguageStandard>
8080
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
8181
<FloatingPointModel>Fast</FloatingPointModel>
8282
</ClCompile>
8383
<Link>
84-
<AdditionalDependencies>dinput.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;ole32.lib;legacy_stdio_definitions.lib;allegro_static_debug.lib;%(AdditionalDependencies)</AdditionalDependencies>
85-
<AdditionalLibraryDirectories>$(SolutionDir)_Bin;$(ProjectDir)external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
84+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;ole32.lib;dinput.lib;dinput8.lib;ddraw.lib;dxguid.lib;winmm.lib;dsound.lib;ws2_32.lib;legacy_stdio_definitions.lib;allegro_static_debug.lib;%(AdditionalDependencies)</AdditionalDependencies>
85+
<AdditionalLibraryDirectories>$(ProjectDir)external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
8686
<GenerateDebugInformation>true</GenerateDebugInformation>
8787
<SubSystem>Windows</SubSystem>
8888
<TargetMachine>MachineX86</TargetMachine>
8989
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
9090
<AdditionalOptions>/ignore:4099 /ignore:4217 /ignore:4049 %(AdditionalOptions)</AdditionalOptions>
91+
<LargeAddressAware>true</LargeAddressAware>
9192
</Link>
9293
<Manifest>
9394
<OutputManifestFile>$(IntDir)$(Configuration).manifest</OutputManifestFile>
@@ -100,7 +101,8 @@
100101
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
101102
<PrecompiledHeader>Use</PrecompiledHeader>
102103
<WarningLevel>Level2</WarningLevel>
103-
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
104+
<DebugInformationFormat>
105+
</DebugInformationFormat>
104106
<ForcedIncludeFiles>StandardIncludes.h;</ForcedIncludeFiles>
105107
<MultiProcessorCompilation>true</MultiProcessorCompilation>
106108
<PrecompiledHeaderFile>StandardIncludes.h</PrecompiledHeaderFile>
@@ -112,18 +114,23 @@
112114
<LanguageStandard>stdcpp17</LanguageStandard>
113115
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
114116
<FloatingPointModel>Fast</FloatingPointModel>
117+
<BufferSecurityCheck>false</BufferSecurityCheck>
118+
<RuntimeTypeInfo>true</RuntimeTypeInfo>
115119
</ClCompile>
116120
<Link>
117-
<AdditionalDependencies>dinput.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;winmm.lib;allegro_static_release.lib;%(AdditionalDependencies)</AdditionalDependencies>
121+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;ole32.lib;dinput.lib;dinput8.lib;ddraw.lib;dxguid.lib;winmm.lib;dsound.lib;ws2_32.lib;legacy_stdio_definitions.lib;allegro_static_release.lib;%(AdditionalDependencies)</AdditionalDependencies>
118122
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
119-
<AdditionalLibraryDirectories>$(SolutionDir)_Bin;$(ProjectDir)external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
123+
<AdditionalLibraryDirectories>$(ProjectDir)external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
120124
<GenerateDebugInformation>false</GenerateDebugInformation>
121125
<SubSystem>Windows</SubSystem>
122126
<OptimizeReferences>true</OptimizeReferences>
123127
<EnableCOMDATFolding>true</EnableCOMDATFolding>
124128
<TargetMachine>MachineX86</TargetMachine>
125129
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
126130
<AdditionalOptions>/ignore:4099 /ignore:4217 /ignore:4049 %(AdditionalOptions)</AdditionalOptions>
131+
<LargeAddressAware>true</LargeAddressAware>
132+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
133+
<FixedBaseAddress>false</FixedBaseAddress>
127134
</Link>
128135
<Manifest>
129136
<OutputManifestFile>$(IntDir)$(Configuration).manifest</OutputManifestFile>
@@ -161,6 +168,7 @@
161168
<ClCompile Include="GUI\GUITextBox.cpp" />
162169
<ClCompile Include="GUI\GUITextPanel.cpp" />
163170
<ClCompile Include="GUI\GUIUtil.cpp" />
171+
<ClCompile Include="GUI\WinUtil.cpp" />
164172
<ClCompile Include="GUI\Wrappers\AllegroBitmap.cpp" />
165173
<ClCompile Include="GUI\Wrappers\AllegroInput.cpp" />
166174
<ClCompile Include="GUI\Wrappers\AllegroScreen.cpp" />
@@ -213,6 +221,7 @@
213221
<ClInclude Include="GUI\GUITextBox.h" />
214222
<ClInclude Include="GUI\GUITextPanel.h" />
215223
<ClInclude Include="GUI\GUIUtil.h" />
224+
<ClInclude Include="GUI\WinUtil.h" />
216225
<ClInclude Include="GUI\Wrappers\AllegroBitmap.h" />
217226
<ClInclude Include="GUI\Wrappers\AllegroInput.h" />
218227
<ClInclude Include="GUI\Wrappers\AllegroScreen.h" />
@@ -223,6 +232,7 @@
223232
<ClInclude Include="System\Reader.h" />
224233
<ClInclude Include="System\RTEError.h" />
225234
<ClInclude Include="System\Serializable.h" />
235+
<ClInclude Include="System\Singleton.h" />
226236
<ClInclude Include="System\StandardIncludes.h" />
227237
<ClInclude Include="System\Timer.h" />
228238
<ClInclude Include="System\TimerMan.h" />

GUIEditor.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<ClCompile Include="GUI\GUI.cpp">
148148
<Filter>GUI</Filter>
149149
</ClCompile>
150+
<ClCompile Include="GUI\WinUtil.cpp">
151+
<Filter>GUI</Filter>
152+
</ClCompile>
150153
</ItemGroup>
151154
<ItemGroup>
152155
<ClInclude Include="Resources\resource.h">
@@ -287,6 +290,12 @@
287290
<ClInclude Include="System\Constants.h">
288291
<Filter>System</Filter>
289292
</ClInclude>
293+
<ClInclude Include="GUI\WinUtil.h">
294+
<Filter>GUI</Filter>
295+
</ClInclude>
296+
<ClInclude Include="System\Singleton.h">
297+
<Filter>System</Filter>
298+
</ClInclude>
290299
</ItemGroup>
291300
<ItemGroup>
292301
<ResourceCompile Include="Resources\Resource.rc">

Main.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
#include "GUIEditorApp.h"
22
#include "GUIEditorLib.h"
3+
#include "ContentFile.h"
4+
#include "TimerMan.h"
35

46
using namespace RTE;
57

68
extern "C" { FILE __iob_func[3] = { *stdin, *stdout, *stderr }; }
7-
//extern HINSTANCE g_hInstance = 0;
8-
//extern HWND g_hWnd = 0;
9+
10+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11+
12+
/// <summary>
13+
/// Quit Handler for Allegro.
14+
/// </summary>
15+
void QuitHandler(void) { g_GUIEditor.OnQuitButton(); }
16+
END_OF_FUNCTION(QuitHandler)
17+
18+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
919

1020
/// <summary>
11-
/// Entry point for the GUI Library editor.
21+
/// Entry point for the GUI editor app.
1222
/// </summary>
1323
int main(int argc, char *argv[]) {
14-
//if (!g_GUIEditor.Initialize()) { return -1; }
24+
allegro_init();
1525

16-
// Get windows settings
17-
//g_hWnd = win_get_window();
18-
//g_hInstance = (HINSTANCE)GetWindowLong(g_hWnd, GWL_HINSTANCE);
26+
// Enable the exit button on the window
27+
LOCK_FUNCTION(QuitHandler);
28+
set_close_button_callback(QuitHandler);
29+
30+
new TimerMan();
31+
g_TimerMan.Create();
32+
33+
new GUIEditorApp();
34+
if (!g_GUIEditor.Initialize()) {
35+
std::exit(EXIT_FAILURE);
36+
}
1937

20-
// Run editor loop
2138
while (true) {
22-
bool bContinue = g_GUIEditor.Update();
23-
if (!bContinue) { break; }
39+
if (!g_GUIEditor.Update()) {
40+
break;
41+
}
2442
}
43+
44+
g_TimerMan.Destroy();
45+
ContentFile::FreeAllLoaded();
46+
47+
std::exit(EXIT_SUCCESS);
2548
return 0;
2649
}
2750

System/ContentFile.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ namespace RTE {
3636
}
3737
BITMAP *returnBitmap = nullptr;
3838

39-
/* Iterator crashes for god knows what reason
4039
std::unordered_map<std::string, BITMAP *>::iterator foundBitmap = m_LoadedBitmaps.find(m_DataPath);
4140
if (foundBitmap != m_LoadedBitmaps.end()) {
4241
returnBitmap = (*foundBitmap).second;
4342
} else {
4443
returnBitmap = LoadAndReleaseBitmap(conversionMode);
4544
m_LoadedBitmaps.insert({ m_DataPath, returnBitmap });
4645
}
47-
*/
48-
49-
returnBitmap = LoadAndReleaseBitmap(conversionMode);
5046

5147
return returnBitmap;
5248
}

System/Reader.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "Reader.h"
2-
#include "RTETools.h"
3-
#include "PresetMan.h"
4-
#include "SettingsMan.h"
2+
#include "RTEError.h"
53

64
namespace RTE {
75

@@ -45,7 +43,7 @@ namespace RTE {
4543
if (firstSlashPos == std::string::npos) { firstSlashPos = m_FilePath.find_first_of('\\'); }
4644

4745
m_DataModuleName = m_FilePath.substr(0, firstSlashPos);
48-
m_DataModuleID = g_PresetMan.GetModuleID(m_DataModuleName);
46+
//m_DataModuleID = g_PresetMan.GetModuleID(m_DataModuleName);
4947

5048
m_Stream = new std::ifstream(fileName);
5149
if (!failOK) { RTEAssert(m_Stream->good(), "Failed to open data file \'" + std::string(fileName) + "\'!"); }
@@ -77,7 +75,7 @@ namespace RTE {
7775

7876
int Reader::GetReadModuleID() const {
7977
// If we have an invalid ID, try to get a valid one based on the name we do have
80-
return (m_DataModuleID < 0) ? g_PresetMan.GetModuleID(m_DataModuleName) : m_DataModuleID;
78+
return 0;//(m_DataModuleID < 0) ? g_PresetMan.GetModuleID(m_DataModuleName) : m_DataModuleID;
8179
}
8280

8381
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -258,7 +256,7 @@ namespace RTE {
258256
if (peek == '\n') {
259257
m_CurrentLine++;
260258
// Only report every few lines
261-
if (m_ReportProgress && (m_CurrentLine % g_SettingsMan.LoadingScreenReportPrecision() == 0)) {
259+
if (m_ReportProgress && (m_CurrentLine % 100 == 0)) {
262260
std::snprintf(report, sizeof(report), "%s%s reading line %i", m_ReportTabs.c_str(), m_FileName.c_str(), m_CurrentLine);
263261
m_ReportProgress(std::string(report), false);
264262
}

0 commit comments

Comments
 (0)