@@ -179,55 +179,117 @@ bool Splash::CreateDeviceResources()
179
179
if (!m_window)
180
180
return false ;
181
181
182
+ ReleaseDeviceResources ();
183
+
182
184
HBITMAP backgroundResource = LoadBitmap (m_windowClass.hInstance , MAKEINTRESOURCE (IDB_BITMAP1));
183
- HBITMAP barResource = LoadBitmap (m_windowClass.hInstance , MAKEINTRESOURCE (IDB_BITMAP2));
185
+ if (backgroundResource == nullptr )
186
+ return false ;
184
187
185
- if (backgroundResource == nullptr || barResource == nullptr )
188
+ HBITMAP barResource = LoadBitmap (m_windowClass.hInstance , MAKEINTRESOURCE (IDB_BITMAP2));
189
+ if (barResource == nullptr )
190
+ {
191
+ DeleteObject (backgroundResource);
186
192
return false ;
193
+ }
187
194
188
195
HDC windowContext = GetDC (m_window);
196
+ if (windowContext == nullptr )
197
+ {
198
+ DeleteObject (barResource);
199
+ DeleteObject (backgroundResource);
200
+ return false ;
201
+ }
189
202
190
- // Background
191
203
HDC sourceContext = CreateCompatibleDC (windowContext);
192
- SelectObject (sourceContext, backgroundResource);
204
+ if (sourceContext == nullptr )
193
205
{
194
- HBITMAP backgroundBitmap = CreateCompatibleBitmap (windowContext, m_width, m_height);
195
- HDC renderContext = CreateCompatibleDC (windowContext);
196
- SelectObject (renderContext, backgroundBitmap);
197
-
198
- BITMAP source{};
199
- GetObject (backgroundResource, sizeof (source), &source);
206
+ ReleaseDC (m_window, windowContext);
207
+ DeleteObject (barResource);
208
+ DeleteObject (backgroundResource);
209
+ return false ;
210
+ }
200
211
201
- SetStretchBltMode (renderContext, HALFTONE);
202
- StretchBlt (renderContext, 0 , 0 , m_width, m_height, sourceContext, 0 , 0 , source.bmWidth , source.bmHeight , SRCCOPY);
212
+ HBITMAP bgBitmap{};
213
+ HDC bgContext{};
214
+ HBITMAP barBitmap{};
215
+ HDC barContext{};
216
+ HRGN barRegion{};
217
+ bool success = false ;
203
218
204
- m_bgBitmap = backgroundBitmap;
205
- m_bgContext = renderContext;
206
- }
219
+ BITMAP source{};
207
220
208
- // Loading bar
209
- SelectObject (sourceContext, barResource);
221
+ do
210
222
{
211
- HBITMAP barBitmap = CreateCompatibleBitmap (windowContext, m_barWidth, m_barHeight);
212
- HDC renderContext = CreateCompatibleDC (windowContext);
213
- SelectObject (renderContext, barBitmap);
223
+ SelectObject (sourceContext, backgroundResource);
224
+
225
+ bgBitmap = CreateCompatibleBitmap (windowContext, m_width, m_height);
226
+ if (bgBitmap == nullptr )
227
+ break ;
214
228
215
- BITMAP source{};
216
- GetObject (barResource, sizeof (source), &source);
229
+ bgContext = CreateCompatibleDC (windowContext);
230
+ if (bgContext == nullptr )
231
+ break ;
217
232
218
- SetStretchBltMode (renderContext, HALFTONE);
219
- StretchBlt (renderContext, 0 , 0 , m_barWidth, m_barHeight, sourceContext, 0 , 0 , source.bmWidth , source.bmHeight , SRCCOPY);
233
+ SelectObject (bgContext, bgBitmap);
220
234
221
- m_barBitmap = barBitmap;
222
- m_barContext = renderContext;
223
- m_barRegion = CreateRectRgn (0 , m_barY, m_width, m_barY + m_barHeight);
224
- }
235
+ if (!GetObject (backgroundResource, sizeof (source), &source))
236
+ break ;
237
+
238
+ SetStretchBltMode (bgContext, HALFTONE);
239
+ if (!StretchBlt (bgContext, 0 , 0 , m_width, m_height, sourceContext, 0 , 0 , source.bmWidth , source.bmHeight , SRCCOPY))
240
+ break ;
241
+
242
+ SelectObject (sourceContext, barResource);
243
+
244
+ barBitmap = CreateCompatibleBitmap (windowContext, m_barWidth, m_barHeight);
245
+ if (barBitmap == nullptr )
246
+ break ;
247
+
248
+ barContext = CreateCompatibleDC (windowContext);
249
+ if (barContext == nullptr )
250
+ break ;
251
+
252
+ SelectObject (barContext, barBitmap);
253
+
254
+ if (!GetObject (barResource, sizeof (source), &source))
255
+ break ;
256
+
257
+ SetStretchBltMode (barContext, HALFTONE);
258
+ if (!StretchBlt (barContext, 0 , 0 , m_barWidth, m_barHeight, sourceContext, 0 , 0 , source.bmWidth , source.bmHeight , SRCCOPY))
259
+ break ;
260
+
261
+ barRegion = CreateRectRgn (0 , m_barY, m_width, m_barY + m_barHeight);
262
+ if (barRegion == nullptr )
263
+ break ;
264
+
265
+ success = true ;
266
+ } while (false );
225
267
226
268
DeleteDC (sourceContext);
269
+ ReleaseDC (m_window, windowContext);
227
270
DeleteObject (barResource);
228
271
DeleteObject (backgroundResource);
229
272
230
- ReleaseDC (m_window, windowContext);
273
+ if (!success)
274
+ {
275
+ if (barRegion)
276
+ DeleteObject (barRegion);
277
+ if (barContext)
278
+ DeleteDC (barContext);
279
+ if (barBitmap)
280
+ DeleteObject (barBitmap);
281
+ if (bgContext)
282
+ DeleteDC (bgContext);
283
+ if (bgBitmap)
284
+ DeleteObject (bgBitmap);
285
+ return false ;
286
+ }
287
+
288
+ m_bgBitmap = bgBitmap;
289
+ m_bgContext = bgContext;
290
+ m_barBitmap = barBitmap;
291
+ m_barContext = barContext;
292
+ m_barRegion = barRegion;
231
293
return true ;
232
294
}
233
295
@@ -521,26 +583,6 @@ void SplashThread::PostRun()
521
583
//
522
584
// /////////////////////////////////////////////////////////////////////////
523
585
524
- #ifdef MTA_DEBUG
525
-
526
- void ShowSplash (HINSTANCE instance)
527
- {
528
- }
529
-
530
- void HideSplash ()
531
- {
532
- }
533
-
534
- void SuspendSplash ()
535
- {
536
- }
537
-
538
- void ResumeSplash ()
539
- {
540
- }
541
-
542
- #else
543
-
544
586
void ShowSplash (HINSTANCE instance)
545
587
{
546
588
if (g_splashThread.Exists ())
@@ -569,8 +611,6 @@ void ResumeSplash()
569
611
g_splash.Show ();
570
612
}
571
613
572
- #endif
573
-
574
614
// /////////////////////////////////////////////////////////////////////////
575
615
//
576
616
// Utility functions.
0 commit comments