Browse Source

Display SDL error messages in UI dialog

This will also end the application in most cases
pull/359/head
Anders Jenbo 7 years ago
parent
commit
a8e4db538f
  1. 6
      3rdParty/Storm/Source/storm.h
  2. 2
      Source/appfat.cpp
  3. 2
      Source/appfat.h
  4. 2
      SourceS/miniwin/com.h
  5. 4
      SourceS/miniwin/misc.h
  6. 4
      SourceX/DiabloUI/art_draw.cpp
  7. 9
      SourceX/DiabloUI/credits.cpp
  8. 5
      SourceX/DiabloUI/diabloui.cpp
  9. 4
      SourceX/DiabloUI/progress.cpp
  10. 4
      SourceX/DiabloUI/text_draw.cpp
  11. 32
      SourceX/dx.cpp
  12. 8
      SourceX/miniwin/dsound.cpp
  13. 2
      SourceX/miniwin/dsound.h
  14. 18
      SourceX/miniwin/misc.cpp
  15. 26
      SourceX/miniwin/thread.cpp
  16. 8
      SourceX/sound.cpp
  17. 38
      SourceX/storm/storm.cpp
  18. 9
      SourceX/storm/storm_dx.cpp
  19. 2
      defs.h

6
3rdParty/Storm/Source/storm.h vendored

@ -728,7 +728,7 @@ SDrawPostClose();
//BOOL STORMAPI SDrawRealizePalette(); //BOOL STORMAPI SDrawRealizePalette();
BOOL STORMAPI SDrawUnlockSurface(int surfacenumber, void *lpSurface, int a3, RECT *lpRect); BOOL STORMAPI SDrawUnlockSurface(int surfacenumber, void *lpSurface, int a3, RECT *lpRect);
BOOL STORMAPI SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETTEENTRY *pPalEntries, int a4); void SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETTEENTRY *pPalEntries, int a4);
BOOL STORMAPI SEvtDispatch(DWORD dwMessageID, DWORD dwFlags, int type, PS_EVT pEvent); BOOL STORMAPI SEvtDispatch(DWORD dwMessageID, DWORD dwFlags, int type, PS_EVT pEvent);
@ -869,10 +869,10 @@ BOOL STORMAPI STransCreateI(void *pBuffer, int width, int height, int bpp, int a
BOOL STORMAPI SVidDestroy(); BOOL STORMAPI SVidDestroy();
BOOL STORMAPI SVidGetSize(HANDLE video, int width, int height, int zero); BOOL STORMAPI SVidGetSize(HANDLE video, int width, int height, int zero);
BOOL STORMAPI SVidInitialize(HANDLE video); BOOL STORMAPI SVidInitialize(HANDLE video);
BOOL STORMAPI SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HANDLE *video); void SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HANDLE *video);
BOOL STORMAPI SVidPlayContinueSingle(HANDLE video, int a2, int a3); BOOL STORMAPI SVidPlayContinueSingle(HANDLE video, int a2, int a3);
BOOL STORMAPI SVidPlayEnd(HANDLE video); void SVidPlayEnd(HANDLE video);
/* SErrDisplayError @ 461 /* SErrDisplayError @ 461
* *

2
Source/appfat.cpp

@ -69,7 +69,7 @@ void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
} }
#endif #endif
void ErrDlg(char *title, char *error, char *log_file_path, int log_line_nr) void ErrDlg(const char *title, const char *error, char *log_file_path, int log_line_nr)
{ {
char text[1024]; char text[1024];

2
Source/appfat.h

@ -22,7 +22,7 @@ void assert_fail(int nLineNo, const char *pszFile, const char *pszFail);
void DDErrMsg(DWORD error_code, int log_line_nr, char *log_file_path); void DDErrMsg(DWORD error_code, int log_line_nr, char *log_file_path);
void DSErrMsg(DWORD error_code, int log_line_nr, char *log_file_path); void DSErrMsg(DWORD error_code, int log_line_nr, char *log_file_path);
void center_window(HWND hDlg); void center_window(HWND hDlg);
void ErrDlg(char *title, char *error, char *log_file_path, int log_line_nr); void ErrDlg(const char *title, const char *error, char *log_file_path, int log_line_nr);
BOOL __stdcall FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, char *text); BOOL __stdcall FuncDlg(HWND hDlg, UINT uMsg, WPARAM wParam, char *text);
void TextDlg(HWND hDlg, char *text); void TextDlg(HWND hDlg, char *text);
void FileErrDlg(const char *error); void FileErrDlg(const char *error);

2
SourceS/miniwin/com.h

@ -7,7 +7,7 @@ struct IDirectSoundBuffer {
virtual void GetStatus(LPDWORD pdwStatus) = 0; virtual void GetStatus(LPDWORD pdwStatus) = 0;
virtual void Play(int lVolume, int lPan) = 0; virtual void Play(int lVolume, int lPan) = 0;
virtual void Stop() = 0; virtual void Stop() = 0;
virtual const char *SetChunk(BYTE *fileData, DWORD dwBytes) = 0; virtual int SetChunk(BYTE *fileData, DWORD dwBytes) = 0;
}; };
typedef IDirectSoundBuffer *LPDIRECTSOUNDBUFFER; typedef IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;

4
SourceS/miniwin/misc.h

@ -186,8 +186,8 @@ WINBOOL WINAPI CloseHandle(HANDLE hObject);
HANDLE WINAPI CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualReset, WINBOOL bInitialState, HANDLE WINAPI CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualReset, WINBOOL bInitialState,
LPCSTR lpName); LPCSTR lpName);
BOOL CloseEvent(HANDLE event); BOOL CloseEvent(HANDLE event);
BOOL WINAPI SetEvent(HANDLE hEvent); void SetEvent(HANDLE hEvent);
BOOL WINAPI ResetEvent(HANDLE hEvent); void ResetEvent(HANDLE hEvent);
int WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds); int WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
WINBOOL WINAPI SetCursorPos(int X, int Y); WINBOOL WINAPI SetCursorPos(int X, int Y);

4
SourceX/DiabloUI/art_draw.cpp

@ -29,12 +29,12 @@ void DrawArt(int screenX, int screenY, Art *art, int nFrame,
if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) { if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) {
if (SDLC_SetSurfaceColors(art->surface, pal_surface->format->palette) <= -1) if (SDLC_SetSurfaceColors(art->surface, pal_surface->format->palette) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
art->palette_version = pal_surface_palette_version; art->palette_version = pal_surface_palette_version;
} }
if (SDL_BlitSurface(art->surface, &src_rect, pal_surface, &dst_rect) <= -1) { if (SDL_BlitSurface(art->surface, &src_rect, pal_surface, &dst_rect) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }

9
SourceX/DiabloUI/credits.cpp

@ -79,17 +79,16 @@ CachedLine PrepareLine(std::size_t index)
// Blit the shadow first: // Blit the shadow first:
SDL_Rect shadow_rect = { SHADOW_OFFSET_X, SHADOW_OFFSET_Y, 0, 0 }; SDL_Rect shadow_rect = { SHADOW_OFFSET_X, SHADOW_OFFSET_Y, 0, 0 };
if (SDL_BlitSurface(text.get(), nullptr, surface.get(), &shadow_rect) <= -1) if (SDL_BlitSurface(text.get(), nullptr, surface.get(), &shadow_rect) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
// Change the text surface color and blit again: // Change the text surface color and blit again:
SDL_Color text_colors[2] = { mask_color, text_color }; SDL_Color text_colors[2] = { mask_color, text_color };
if (SDLC_SetSurfaceColors(text.get(), text_colors, 0, 2) <= -1) if (SDLC_SetSurfaceColors(text.get(), text_colors, 0, 2) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
SDLC_SetColorKey(text.get(), 0); SDLC_SetColorKey(text.get(), 0);
if (SDL_BlitSurface(text.get(), nullptr, surface.get(), nullptr) <= -1) if (SDL_BlitSurface(text.get(), nullptr, surface.get(), nullptr) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
} }
return CachedLine(index, std::move(surface)); return CachedLine(index, std::move(surface));
@ -236,7 +235,7 @@ void CreditsRenderer::Render()
SDL_Rect dest_rect = { dest_x, dest_y, 0, 0 }; SDL_Rect dest_rect = { dest_x, dest_y, 0, 0 };
if (SDL_BlitSurface(line.surface.get(), nullptr, pal_surface, &dest_rect) <= -1) if (SDL_BlitSurface(line.surface.get(), nullptr, pal_surface, &dest_rect) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
} }
SDL_SetClipRect(pal_surface, nullptr); SDL_SetClipRect(pal_surface, nullptr);
} }

5
SourceX/DiabloUI/diabloui.cpp

@ -245,8 +245,9 @@ bool UiFocusNavigation(SDL_Event *event)
char *clipboard = SDL_GetClipboardText(); char *clipboard = SDL_GetClipboardText();
if (clipboard == NULL) { if (clipboard == NULL) {
SDL_Log(SDL_GetError()); SDL_Log(SDL_GetError());
} else {
selhero_CatToName(clipboard, UiTextInput, UiTextInputLen);
} }
selhero_CatToName(clipboard, UiTextInput, UiTextInputLen);
} }
return true; return true;
#endif #endif
@ -353,7 +354,7 @@ void UiInitialize()
LoadArtFonts(); LoadArtFonts();
if (ArtCursor.surface != nullptr) { if (ArtCursor.surface != nullptr) {
if (SDL_ShowCursor(SDL_DISABLE) <= -1) { if (SDL_ShowCursor(SDL_DISABLE) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
} }

4
SourceX/DiabloUI/progress.cpp

@ -67,12 +67,12 @@ void progress_Render(BYTE progress)
static_cast<decltype(SDL_Rect().y)>(SCREEN_Y + y + 8), static_cast<decltype(SDL_Rect().y)>(SCREEN_Y + y + 8),
SCREEN_WIDTH, SCREEN_HEIGHT }; SCREEN_WIDTH, SCREEN_HEIGHT };
if (SDL_BlitSurface(msgSurface, NULL, pal_surface, &dsc_rect) <= -1) { if (SDL_BlitSurface(msgSurface, NULL, pal_surface, &dsc_rect) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
dsc_rect.x = SCREEN_X + GetCenterOffset(textWidth) - 1; dsc_rect.x = SCREEN_X + GetCenterOffset(textWidth) - 1;
dsc_rect.y = SCREEN_Y + y + 99 + 4; dsc_rect.y = SCREEN_Y + y + 99 + 4;
if (SDL_BlitSurface(cancleSurface, NULL, pal_surface, &dsc_rect) <= -1) { if (SDL_BlitSurface(cancleSurface, NULL, pal_surface, &dsc_rect) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
} }

4
SourceX/DiabloUI/text_draw.cpp

@ -57,9 +57,9 @@ void DrawTTF(const char *text, const SDL_Rect &rect, int flags,
++shadow_rect.x; ++shadow_rect.x;
++shadow_rect.y; ++shadow_rect.y;
if (SDL_BlitSurface(shadow_surface, nullptr, pal_surface, &shadow_rect) <= -1) if (SDL_BlitSurface(shadow_surface, nullptr, pal_surface, &shadow_rect) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
if (SDL_BlitSurface(text_surface, nullptr, pal_surface, &dest_rect) <= -1) if (SDL_BlitSurface(text_surface, nullptr, pal_surface, &dest_rect) <= -1)
SDL_Log(SDL_GetError()); ErrSdl();
} }
void DrawArtStr(const char *text, const SDL_Rect &rect, int flags, bool drawTextCursor) void DrawArtStr(const char *text, const SDL_Rect &rect, int flags, bool drawTextCursor)

32
SourceX/dx.cpp

@ -44,15 +44,13 @@ void dx_create_back_buffer()
{ {
pal_surface = SDL_CreateRGBSurfaceWithFormat(0, BUFFER_WIDTH, BUFFER_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8); pal_surface = SDL_CreateRGBSurfaceWithFormat(0, BUFFER_WIDTH, BUFFER_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8);
if (pal_surface == NULL) { if (pal_surface == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
UiErrorOkDialog("SDL Error", SDL_GetError());
} }
gpBuffer = (BYTE *)pal_surface->pixels; gpBuffer = (BYTE *)pal_surface->pixels;
if (SDLC_SetSurfaceColors(pal_surface, palette) <= -1) { if (SDLC_SetSurfaceColors(pal_surface, palette) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
UiErrorOkDialog("SDL Error", SDL_GetError());
} }
pal_surface_palette_version = 1; pal_surface_palette_version = 1;
@ -66,19 +64,18 @@ void dx_create_primary_surface()
if (renderer) { if (renderer) {
int width, height; int width, height;
if (SDL_GetRendererOutputSize(renderer, &width, &height) <= -1) { if (SDL_GetRendererOutputSize(renderer, &width, &height) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
Uint32 format; Uint32 format;
if (SDL_QueryTexture(texture, &format, nullptr, nullptr, nullptr) < 0) if (SDL_QueryTexture(texture, &format, nullptr, nullptr, nullptr) < 0)
SDL_Log(SDL_GetError()); ErrSdl();
surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format); surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format);
} else { } else {
surface = SDL_GetWindowSurface(window); surface = SDL_GetWindowSurface(window);
} }
#endif #endif
if (surface == NULL) { if (surface == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
UiErrorOkDialog("SDL Error", SDL_GetError());
} }
} }
@ -178,8 +175,7 @@ void CreatePalette()
{ {
palette = SDL_AllocPalette(256); palette = SDL_AllocPalette(256);
if (palette == NULL) { if (palette == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
UiErrorOkDialog("SDL Error", SDL_GetError());
} }
} }
@ -200,9 +196,7 @@ void BltFast(DWORD dwX, DWORD dwY, LPRECT lpSrcRect)
// Convert from 8-bit to 32-bit // Convert from 8-bit to 32-bit
if (SDL_BlitSurface(pal_surface, &src_rect, surface, &dst_rect) <= -1) { if (SDL_BlitSurface(pal_surface, &src_rect, surface, &dst_rect) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
UiErrorOkDialog("SDL Error", SDL_GetError());
return;
} }
bufferUpdated = true; bufferUpdated = true;
@ -218,30 +212,30 @@ void RenderPresent()
#ifdef USE_SDL1 #ifdef USE_SDL1
if (SDL_Flip(surface) <= -1) { if (SDL_Flip(surface) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
#else #else
if (renderer) { if (renderer) {
if (SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch) <= -1) { //pitch is 2560 if (SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch) <= -1) { //pitch is 2560
SDL_Log(SDL_GetError()); ErrSdl();
} }
// Clear buffer to avoid artifacts in case the window was resized // Clear buffer to avoid artifacts in case the window was resized
if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) <= -1) { // TODO only do this if window was resized if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) <= -1) { // TODO only do this if window was resized
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (SDL_RenderClear(renderer) <= -1) { if (SDL_RenderClear(renderer) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (SDL_RenderCopy(renderer, texture, NULL, NULL) <= -1) { if (SDL_RenderCopy(renderer, texture, NULL, NULL) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} else { } else {
if (SDL_UpdateWindowSurface(window) <= -1) { if (SDL_UpdateWindowSurface(window) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
#endif #endif

8
SourceX/miniwin/dsound.cpp

@ -46,19 +46,19 @@ void DirectSoundBuffer::Stop()
} }
}; };
const char *DirectSoundBuffer::SetChunk(BYTE *fileData, DWORD dwBytes) int DirectSoundBuffer::SetChunk(BYTE *fileData, DWORD dwBytes)
{ {
SDL_RWops *buf1 = SDL_RWFromConstMem(fileData, dwBytes); SDL_RWops *buf1 = SDL_RWFromConstMem(fileData, dwBytes);
if (buf1 == NULL) { if (buf1 == NULL) {
return SDL_GetError(); return -1;
} }
chunk = Mix_LoadWAV_RW(buf1, 1); chunk = Mix_LoadWAV_RW(buf1, 1);
if (chunk == NULL) { if (chunk == NULL) {
return SDL_GetError(); return -1;
} }
return NULL; return 0;
}; };
} // namespace dvl } // namespace dvl

2
SourceX/miniwin/dsound.h

@ -10,7 +10,7 @@ public:
void GetStatus(LPDWORD pdwStatus) override; void GetStatus(LPDWORD pdwStatus) override;
void Play(int lVolume, int lPan) override; void Play(int lVolume, int lPan) override;
void Stop() override; void Stop() override;
const char *SetChunk(BYTE *fileData, DWORD dwBytes) override; int SetChunk(BYTE *fileData, DWORD dwBytes) override;
private: private:
Mix_Chunk *chunk; Mix_Chunk *chunk;

18
SourceX/miniwin/misc.cpp

@ -129,17 +129,10 @@ WINBOOL DeleteFileA(LPCSTR lpFileName)
return true; return true;
} }
void FakeWMDestroy()
{
init_cleanup();
PostMessageA(NULL, DVL_WM_QUERYENDSESSION, 0, 0);
}
bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight) bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
{ {
if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) <= -1) { if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
return false;
} }
atexit(SDL_Quit); atexit(SDL_Quit);
@ -185,9 +178,8 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
window = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags); window = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags);
#endif #endif
if (window == NULL) { if (window == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
atexit(FakeWMDestroy);
if (upscale) { if (upscale) {
#ifdef USE_SDL1 #ifdef USE_SDL1
@ -195,16 +187,16 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
#else #else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if (renderer == NULL) { if (renderer == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, nWidth, nHeight); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, nWidth, nHeight);
if (texture == NULL) { if (texture == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (SDL_RenderSetLogicalSize(renderer, nWidth, nHeight) <= -1) { if (SDL_RenderSetLogicalSize(renderer, nWidth, nHeight) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
#endif #endif
} }

26
SourceX/miniwin/thread.cpp

@ -44,7 +44,7 @@ uintptr_t DVL_beginthreadex(void *_Security, unsigned _StackSize, unsigned (*_St
SDL_Thread *ret = SDL_CreateThread(thread_translate, NULL, ft); SDL_Thread *ret = SDL_CreateThread(thread_translate, NULL, ft);
#endif #endif
if (ret == NULL) { if (ret == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
*_ThrdAddr = SDL_GetThreadID(ret); *_ThrdAddr = SDL_GetThreadID(ret);
threads.insert((uintptr_t)ret); threads.insert((uintptr_t)ret);
@ -74,7 +74,7 @@ void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
{ {
SDL_mutex *m = SDL_CreateMutex(); SDL_mutex *m = SDL_CreateMutex();
if (m == NULL) { if (m == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
*lpCriticalSection = m; *lpCriticalSection = m;
} }
@ -82,14 +82,14 @@ void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
void EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection) void EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
{ {
if (SDL_LockMutex(*((SDL_mutex **)lpCriticalSection)) <= -1) { if (SDL_LockMutex(*((SDL_mutex **)lpCriticalSection)) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
void LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection) void LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
{ {
if (SDL_UnlockMutex(*((SDL_mutex **)lpCriticalSection)) <= -1) { if (SDL_UnlockMutex(*((SDL_mutex **)lpCriticalSection)) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
@ -119,11 +119,11 @@ HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualRese
ret = (struct event_emul *)malloc(sizeof(struct event_emul)); ret = (struct event_emul *)malloc(sizeof(struct event_emul));
ret->mutex = SDL_CreateMutex(); ret->mutex = SDL_CreateMutex();
if (ret->mutex == NULL) { if (ret->mutex == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
ret->cond = SDL_CreateCond(); ret->cond = SDL_CreateCond();
if (ret->cond == NULL) { if (ret->cond == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
events.insert((uintptr_t)ret); events.insert((uintptr_t)ret);
return ret; return ret;
@ -141,31 +141,27 @@ BOOL CloseEvent(HANDLE hObject)
return true; return true;
} }
BOOL SetEvent(HANDLE hEvent) void SetEvent(HANDLE hEvent)
{ {
struct event_emul *e = (struct event_emul *)hEvent; struct event_emul *e = (struct event_emul *)hEvent;
if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondSignal(e->cond) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) { if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondSignal(e->cond) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
return 0;
} }
return 1;
} }
BOOL ResetEvent(HANDLE hEvent) void ResetEvent(HANDLE hEvent)
{ {
struct event_emul *e = (struct event_emul *)hEvent; struct event_emul *e = (struct event_emul *)hEvent;
if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondWaitTimeout(e->cond, e->mutex, 0) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) { if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondWaitTimeout(e->cond, e->mutex, 0) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
return 0;
} }
return 1;
} }
static int wait_for_sdl_cond(HANDLE hHandle, DWORD dwMilliseconds) static int wait_for_sdl_cond(HANDLE hHandle, DWORD dwMilliseconds)
{ {
struct event_emul *e = (struct event_emul *)hHandle; struct event_emul *e = (struct event_emul *)hHandle;
if (SDL_LockMutex(e->mutex) <= -1) { if (SDL_LockMutex(e->mutex) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
int ret; int ret;
if (dwMilliseconds == DVL_INFINITE) if (dwMilliseconds == DVL_INFINITE)

8
SourceX/sound.cpp

@ -92,7 +92,7 @@ TSnd *sound_file_load(char *path)
BYTE *wave_file; BYTE *wave_file;
TSnd *pSnd; TSnd *pSnd;
DWORD dwBytes; DWORD dwBytes;
const char *error; int error;
WOpenFile(path, &file, false); WOpenFile(path, &file, false);
pSnd = (TSnd *)DiabloAllocPtr(sizeof(TSnd)); pSnd = (TSnd *)DiabloAllocPtr(sizeof(TSnd));
@ -108,8 +108,8 @@ TSnd *sound_file_load(char *path)
error = pSnd->DSB->SetChunk(wave_file, dwBytes); error = pSnd->DSB->SetChunk(wave_file, dwBytes);
WCloseFile(file); WCloseFile(file);
mem_free_dbg(wave_file); mem_free_dbg(wave_file);
if (error != NULL) { if (error != 0) {
app_fatal("%s: %s", pSnd->sound_path, error); ErrSdl();
} }
return pSnd; return pSnd;
@ -210,7 +210,7 @@ void music_start(int nTrack)
musicRw = SDL_RWFromConstMem(musicBuffer, bytestoread); musicRw = SDL_RWFromConstMem(musicBuffer, bytestoread);
if (musicRw == NULL) { if (musicRw == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
music = Mix_LoadMUSType_RW(musicRw, MUS_NONE, 1); music = Mix_LoadMUSType_RW(musicRw, MUS_NONE, 1);
Mix_VolumeMusic(MIX_MAX_VOLUME - MIX_MAX_VOLUME * sglMusicVolume / VOLUME_MIN); Mix_VolumeMusic(MIX_MAX_VOLUME - MIX_MAX_VOLUME * sglMusicVolume / VOLUME_MIN);

38
SourceX/storm/storm.cpp

@ -77,6 +77,7 @@ BOOL SFileDdaBeginEx(HANDLE hFile, DWORD flags, DWORD mask, unsigned __int32 lDi
SDL_RWops *rw = SDL_RWFromConstMem(SFXbuffer, bytestoread); SDL_RWops *rw = SDL_RWFromConstMem(SFXbuffer, bytestoread);
if (rw == NULL) { if (rw == NULL) {
SDL_Log(SDL_GetError()); SDL_Log(SDL_GetError());
return false;
} }
SFileChunk = Mix_LoadWAV_RW(rw, 1); SFileChunk = Mix_LoadWAV_RW(rw, 1);
free(SFXbuffer); free(SFXbuffer);
@ -526,10 +527,10 @@ private:
static AudioQueue *sVidAudioQueue = new AudioQueue(); static AudioQueue *sVidAudioQueue = new AudioQueue();
#endif #endif
BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HANDLE *video) void SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HANDLE *video)
{ {
if (flags & 0x10000 || flags & 0x20000000) { if (flags & 0x10000 || flags & 0x20000000) {
return false; return;
} }
SVidLoop = flags & 0x40000; SVidLoop = flags & 0x40000;
@ -549,7 +550,7 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA
SVidSMK = smk_open_memory(SVidBuffer, bytestoread); SVidSMK = smk_open_memory(SVidBuffer, bytestoread);
if (SVidSMK == NULL) { if (SVidSMK == NULL) {
return false; return;
} }
unsigned char channels[7], depth[7]; unsigned char channels[7], depth[7];
@ -568,17 +569,13 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA
#ifdef USE_SDL1 #ifdef USE_SDL1
sVidAudioQueue->Subscribe(&audioFormat); sVidAudioQueue->Subscribe(&audioFormat);
if (SDL_OpenAudio(&audioFormat, NULL) != 0) { if (SDL_OpenAudio(&audioFormat, NULL) != 0) {
SDL_Log(SDL_GetError()); ErrSdl();
SVidRestartMixer();
return false;
} }
SDL_PauseAudio(0); SDL_PauseAudio(0);
#else #else
deviceId = SDL_OpenAudioDevice(NULL, 0, &audioFormat, NULL, 0); deviceId = SDL_OpenAudioDevice(NULL, 0, &audioFormat, NULL, 0);
if (deviceId == 0) { if (deviceId == 0) {
SDL_Log(SDL_GetError()); ErrSdl();
SVidRestartMixer();
return false;
} }
SDL_PauseAudioDevice(deviceId, 0); /* start audio playing. */ SDL_PauseAudioDevice(deviceId, 0); /* start audio playing. */
@ -598,10 +595,10 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, SVidWidth, SVidHeight); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, SVidWidth, SVidHeight);
if (texture == NULL) { if (texture == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (SDL_RenderSetLogicalSize(renderer, SVidWidth, SVidHeight) <= -1) { if (SDL_RenderSetLogicalSize(renderer, SVidWidth, SVidHeight) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
#endif #endif
@ -616,23 +613,18 @@ BOOL SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA
SVidWidth, SVidWidth,
SDL_PIXELFORMAT_INDEX8); SDL_PIXELFORMAT_INDEX8);
if (SVidSurface == NULL) { if (SVidSurface == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
SVidPalette = SDL_AllocPalette(256); SVidPalette = SDL_AllocPalette(256);
if (SVidPalette == NULL) { if (SVidPalette == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (SDLC_SetSurfaceColors(SVidSurface, SVidPalette) <= -1) { if (SDLC_SetSurfaceColors(SVidSurface, SVidPalette) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
if (HaveAudio())
SVidRestartMixer();
return false;
} }
SVidFrameEnd = SDL_GetTicks() * 1000 + SVidFrameLength; SVidFrameEnd = SDL_GetTicks() * 1000 + SVidFrameLength;
return true;
} }
BOOL SVidLoadNextFrame() BOOL SVidLoadNextFrame()
@ -748,7 +740,7 @@ BOOL SVidPlayContinue(void)
return SVidLoadNextFrame(); return SVidLoadNextFrame();
} }
BOOL SVidPlayEnd(HANDLE video) void SVidPlayEnd(HANDLE video)
{ {
if (HaveAudio()) { if (HaveAudio()) {
#ifdef USE_SDL1 #ifdef USE_SDL1
@ -785,15 +777,13 @@ BOOL SVidPlayEnd(HANDLE video)
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH, SCREEN_HEIGHT); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH, SCREEN_HEIGHT);
if (texture == NULL) { if (texture == NULL) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
if (renderer && SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT) <= -1) { if (renderer && SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
} }
} }
#endif #endif
return true;
} }
DWORD SErrGetLastError() DWORD SErrGetLastError()

9
SourceX/storm/storm_dx.cpp

@ -6,7 +6,7 @@
namespace dvl { namespace dvl {
BOOL SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETTEENTRY *pPalEntries, int a4) void SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETTEENTRY *pPalEntries, int a4)
{ {
assert(firstentry == 0); assert(firstentry == 0);
assert(numentries == 256); assert(numentries == 256);
@ -25,12 +25,9 @@ BOOL SDrawUpdatePalette(unsigned int firstentry, unsigned int numentries, PALETT
assert(palette); assert(palette);
if (SDLC_SetSurfaceAndPaletteColors(pal_surface, palette, colors, firstentry, numentries) <= -1) { if (SDLC_SetSurfaceAndPaletteColors(pal_surface, palette, colors, firstentry, numentries) <= -1) {
SDL_Log(SDL_GetError()); ErrSdl();
return false;
} }
++pal_surface_palette_version; pal_surface_palette_version++;
return true;
} }
} // namespace dvl } // namespace dvl

2
defs.h

@ -163,3 +163,5 @@
#define SwapLE32 SDL_SwapLE32 #define SwapLE32 SDL_SwapLE32
#define SwapLE16 SDL_SwapLE16 #define SwapLE16 SDL_SwapLE16
#define ErrSdl() ErrDlg("SDL Error", SDL_GetError(), __FILE__, __LINE__)

Loading…
Cancel
Save