mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Fallback to displaying errors in message box if can't show in chat
This commit is contained in:
parent
3779be0e81
commit
23772e1962
@ -1,7 +1,7 @@
|
||||
#include "AsyncDownloader.h"
|
||||
#include "Platform.h"
|
||||
#include "Funcs.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Stream.h"
|
||||
#include "GameStructs.h"
|
||||
|
||||
@ -41,7 +41,7 @@ static void AsyncRequestList_Prepend(struct AsyncRequestList* list, struct Async
|
||||
}
|
||||
|
||||
static void AsyncRequestList_RemoveAt(struct AsyncRequestList* list, int i) {
|
||||
if (i < 0 || i >= list->Count) ErrorHandler_Fail("Tried to remove element at list end");
|
||||
if (i < 0 || i >= list->Count) Logger_Abort("Tried to remove element at list end");
|
||||
|
||||
for (; i < list->Count - 1; i++) {
|
||||
list->Requests[i] = list->Requests[i + 1];
|
||||
|
12
src/Audio.c
12
src/Audio.c
@ -1,5 +1,5 @@
|
||||
#include "Audio.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Platform.h"
|
||||
#include "Event.h"
|
||||
#include "Block.h"
|
||||
@ -167,7 +167,7 @@ static void Soundboard_Init(struct Soundboard* board, const String* boardName, S
|
||||
res = Sound_ReadWave(&file, snd);
|
||||
|
||||
if (res) {
|
||||
Chat_LogError2(res, "decoding", &file);
|
||||
Logger_Warn2(res, "decoding", &file);
|
||||
Mem_Free(snd->Data);
|
||||
snd->Data = NULL;
|
||||
snd->DataSize = 0;
|
||||
@ -206,7 +206,7 @@ static struct SoundOutput monoOutputs[AUDIO_MAX_HANDLES] = { SOUND_INV, SOUND_
|
||||
static struct SoundOutput stereoOutputs[AUDIO_MAX_HANDLES] = { SOUND_INV, SOUND_INV, SOUND_INV, SOUND_INV, SOUND_INV, SOUND_INV };
|
||||
|
||||
CC_NOINLINE static void Sounds_Fail(ReturnCode res) {
|
||||
Chat_LogError(res, "playing sounds");
|
||||
Logger_Warn(res, "playing sounds");
|
||||
Chat_AddRaw("&cDisabling sounds");
|
||||
Audio_SetSounds(0);
|
||||
}
|
||||
@ -466,15 +466,15 @@ static void Music_RunLoop(void) {
|
||||
Platform_Log1("playing music file: %s", &file);
|
||||
|
||||
res = Stream_OpenFile(&stream, &path);
|
||||
if (res) { Chat_LogError2(res, "opening", &path); break; }
|
||||
if (res) { Logger_Warn2(res, "opening", &path); break; }
|
||||
|
||||
res = Music_PlayOgg(&stream);
|
||||
if (res) {
|
||||
Chat_LogError2(res, "playing", &path); stream.Close(&stream); break;
|
||||
Logger_Warn2(res, "playing", &path); stream.Close(&stream); break;
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", &path); break; }
|
||||
if (res) { Logger_Warn2(res, "closing", &path); break; }
|
||||
|
||||
if (music_pendingStop) break;
|
||||
delay = 1000 * 120 + Random_Range(&rnd, 0, 1000 * 300);
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "PackedCol.h"
|
||||
#include "ExtMath.h"
|
||||
#include "Deflate.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Stream.h"
|
||||
#include "Errors.h"
|
||||
#include "Utils.h"
|
||||
@ -119,7 +119,7 @@ static void Png_Reconstruct(uint8_t type, uint8_t bytesPerPixel, uint8_t* line,
|
||||
return;
|
||||
|
||||
default:
|
||||
ErrorHandler_Fail("PNG scanline has invalid filter type");
|
||||
Logger_Abort("PNG scanline has invalid filter type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
16
src/Chat.c
16
src/Chat.c
@ -3,7 +3,7 @@
|
||||
#include "Platform.h"
|
||||
#include "Event.h"
|
||||
#include "Game.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "ServerConnection.h"
|
||||
#include "World.h"
|
||||
#include "Inventory.h"
|
||||
@ -34,7 +34,7 @@ static TimeMS* Chat_LogTimes = Chat_DefaultLogTimes;
|
||||
static int Chat_LogTimesMax = CHAT_LOGTIMES_DEF_ELEMS, Chat_LogTimesCount;
|
||||
|
||||
TimeMS Chat_GetLogTime(int i) {
|
||||
if (i < 0 || i >= Chat_LogTimesCount) ErrorHandler_Fail("Tried to get time past LogTime end");
|
||||
if (i < 0 || i >= Chat_LogTimesCount) Logger_Abort("Tried to get time past LogTime end");
|
||||
return Chat_LogTimes[i];
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ static void Chat_CloseLog(void) {
|
||||
if (!Chat_LogStream.Meta.File) return;
|
||||
|
||||
res = Chat_LogStream.Close(&Chat_LogStream);
|
||||
if (res) { Chat_LogError2(res, "closing", &Chat_LogPath); }
|
||||
if (res) { Logger_Warn2(res, "closing", &Chat_LogPath); }
|
||||
}
|
||||
|
||||
static bool Chat_AllowedLogChar(char c) {
|
||||
@ -113,7 +113,7 @@ static void Chat_OpenLog(struct DateTime* now) {
|
||||
res = File_Append(&file, path);
|
||||
if (res && res != ReturnCode_FileShareViolation) {
|
||||
Chat_DisableLogging();
|
||||
Chat_LogError2(res, "appending to", path); return;
|
||||
Logger_Warn2(res, "appending to", path); return;
|
||||
}
|
||||
|
||||
if (res == ReturnCode_FileShareViolation) continue;
|
||||
@ -150,15 +150,9 @@ static void Chat_AppendLog(const String* text) {
|
||||
res = Stream_WriteLine(&Chat_LogStream, &str);
|
||||
if (!res) return;
|
||||
Chat_DisableLogging();
|
||||
Chat_LogError2(res, "writing to", &Chat_LogPath);
|
||||
Logger_Warn2(res, "writing to", &Chat_LogPath);
|
||||
}
|
||||
|
||||
void Chat_LogError(ReturnCode result, const char* place) {
|
||||
Chat_Add4("&cError %h when %c", &result, place, NULL, NULL);
|
||||
}
|
||||
void Chat_LogError2(ReturnCode result, const char* place, const String* path) {
|
||||
Chat_Add4("&cError %h when %c '%s'", &result, place, path, NULL);
|
||||
}
|
||||
void Chat_Add1(const char* format, const void* a1) {
|
||||
Chat_Add4(format, a1, NULL, NULL, NULL);
|
||||
}
|
||||
|
@ -62,8 +62,6 @@ CC_API void Chat_AddOf(const String* text, MsgType type);
|
||||
/* Shorthand for Chat_AddOf(String_FromReadonly(raw), MSG_TYPE_NORMAL) */
|
||||
void Chat_AddRaw(const char* raw);
|
||||
|
||||
CC_NOINLINE void Chat_LogError(ReturnCode result, const char* place);
|
||||
CC_NOINLINE void Chat_LogError2(ReturnCode result, const char* place, const String* path);
|
||||
void Chat_Add1(const char* format, const void* a1);
|
||||
void Chat_Add2(const char* format, const void* a1, const void* a2);
|
||||
void Chat_Add3(const char* format, const void* a1, const void* a2, const void* a3);
|
||||
|
@ -202,7 +202,7 @@
|
||||
<ClInclude Include="Entity.h" />
|
||||
<ClInclude Include="EntityComponents.h" />
|
||||
<ClInclude Include="EnvRenderer.h" />
|
||||
<ClInclude Include="ErrorHandler.h" />
|
||||
<ClInclude Include="Logger.h" />
|
||||
<ClInclude Include="Errors.h" />
|
||||
<ClInclude Include="Event.h" />
|
||||
<ClInclude Include="Formats.h" />
|
||||
@ -308,7 +308,7 @@
|
||||
<ClCompile Include="Vectors.c" />
|
||||
<ClCompile Include="Vorbis.c" />
|
||||
<ClCompile Include="Widgets.c" />
|
||||
<ClCompile Include="ErrorHandler.c" />
|
||||
<ClCompile Include="Logger.c" />
|
||||
<ClCompile Include="Window.c" />
|
||||
<ClCompile Include="World.c" />
|
||||
<ClCompile Include="_autofit.c" />
|
||||
|
@ -150,9 +150,6 @@
|
||||
<ClInclude Include="VertexStructs.h">
|
||||
<Filter>Header Files\Graphics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ErrorHandler.h">
|
||||
<Filter>Header Files\Platform</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="World.h">
|
||||
<Filter>Header Files\Map</Filter>
|
||||
</ClInclude>
|
||||
@ -318,6 +315,9 @@
|
||||
<ClInclude Include="Inventory.h">
|
||||
<Filter>Header Files\Game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Logger.h">
|
||||
<Filter>Header Files\Platform</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="String.c">
|
||||
@ -455,9 +455,6 @@
|
||||
<ClCompile Include="Platform.c">
|
||||
<Filter>Source Files\Platform</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ErrorHandler.c">
|
||||
<Filter>Source Files\Platform</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MapGenerator.c">
|
||||
<Filter>Source Files\Map</Filter>
|
||||
</ClCompile>
|
||||
@ -566,5 +563,8 @@
|
||||
<ClCompile Include="Inventory.c">
|
||||
<Filter>Source Files\Game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Logger.c">
|
||||
<Filter>Source Files\Platform</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -193,7 +193,7 @@ static void Huffman_Build(struct HuffmanTable* table, uint8_t* bitLens, int coun
|
||||
bl_count[0] = 0;
|
||||
for (i = 1; i < INFLATE_MAX_BITS; i++) {
|
||||
if (bl_count[i] > (1 << i)) {
|
||||
ErrorHandler_Fail("Too many huffman codes for bit length");
|
||||
Logger_Abort("Too many huffman codes for bit length");
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ static int Huffman_Decode(struct InflateState* state, struct HuffmanTable* table
|
||||
}
|
||||
}
|
||||
|
||||
ErrorHandler_Fail("DEFLATE - Invalid huffman code");
|
||||
Logger_Abort("DEFLATE - Invalid huffman code");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ static int Huffman_Unsafe_Decode_Slow(struct InflateState* state, struct Huffman
|
||||
}
|
||||
}
|
||||
|
||||
ErrorHandler_Fail("DEFLATE - Invalid huffman code");
|
||||
Logger_Abort("DEFLATE - Invalid huffman code");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -496,7 +496,7 @@ void Inflate_Process(struct InflateState* state) {
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
ErrorHandler_Fail("DEFLATE - Invalid block type");
|
||||
Logger_Abort("DEFLATE - Invalid block type");
|
||||
} break;
|
||||
|
||||
}
|
||||
@ -509,7 +509,7 @@ void Inflate_Process(struct InflateState* state) {
|
||||
nlen = Inflate_ReadBits(state, 16);
|
||||
|
||||
if (len != (nlen ^ 0xFFFFUL)) {
|
||||
ErrorHandler_Fail("DEFLATE - Uncompressed block LEN check failed");
|
||||
Logger_Abort("DEFLATE - Uncompressed block LEN check failed");
|
||||
}
|
||||
state->Index = len; /* Reuse for 'uncompressed length' */
|
||||
state->State = INFLATE_STATE_UNCOMPRESSED_DATA;
|
||||
@ -602,7 +602,7 @@ void Inflate_Process(struct InflateState* state) {
|
||||
case 16:
|
||||
Inflate_EnsureBits(state, 2);
|
||||
repeatCount = Inflate_ReadBits(state, 2);
|
||||
if (!state->Index) ErrorHandler_Fail("DEFLATE - Tried to repeat invalid byte");
|
||||
if (!state->Index) Logger_Abort("DEFLATE - Tried to repeat invalid byte");
|
||||
repeatCount += 3; repeatValue = state->Buffer[state->Index - 1];
|
||||
break;
|
||||
|
||||
@ -621,7 +621,7 @@ void Inflate_Process(struct InflateState* state) {
|
||||
|
||||
count = state->NumLits + state->NumDists;
|
||||
if (state->Index + repeatCount > count) {
|
||||
ErrorHandler_Fail("DEFLATE - Tried to repeat past end");
|
||||
Logger_Abort("DEFLATE - Tried to repeat past end");
|
||||
}
|
||||
|
||||
Mem_Set(&state->Buffer[state->Index], repeatValue, repeatCount);
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "Funcs.h"
|
||||
#include "Platform.h"
|
||||
#include "ExtMath.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Bitmap.h"
|
||||
#include "Game.h"
|
||||
#include "Event.h"
|
||||
@ -679,7 +679,7 @@ static void Drawer2D_TextureChanged(void* obj, struct Stream* src, const String*
|
||||
if (!String_CaselessEqualsConst(name, "default.png")) return;
|
||||
|
||||
if ((res = Png_Decode(&bmp, src))) {
|
||||
Chat_LogError2(res, "decoding", name);
|
||||
Logger_Warn2(res, "decoding", name);
|
||||
Mem_Free(bmp.Scan0);
|
||||
} else {
|
||||
Drawer2D_SetFontBitmap(&bmp);
|
||||
@ -706,7 +706,7 @@ static void Drawer2D_CheckFont(void) {
|
||||
String_Copy(&Drawer2D_FontName, &default_fonts[i]);
|
||||
return;
|
||||
}
|
||||
ErrorHandler_Fail("Unable to init default font");
|
||||
Logger_Abort("Unable to init default font");
|
||||
}
|
||||
|
||||
static void Drawer2D_Init(void) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "Gui.h"
|
||||
#include "Stream.h"
|
||||
#include "Bitmap.h"
|
||||
#include "ErrorHandler.h"
|
||||
|
||||
NameMode Entities_NameMode;
|
||||
ShadowMode Entities_ShadowMode;
|
||||
@ -703,7 +704,7 @@ static void Player_CheckSkin(struct Player* p) {
|
||||
|
||||
if ((res = Png_Decode(&bmp, &mem))) {
|
||||
url = String_FromRawArray(item.URL);
|
||||
Chat_LogError2(res, "decoding", &url);
|
||||
Logger_Warn2(res, "decoding", &url);
|
||||
Mem_Free(bmp.Scan0); return;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "Event.h"
|
||||
#include "Utils.h"
|
||||
#include "Game.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Stream.h"
|
||||
#include "Block.h"
|
||||
#include "Event.h"
|
||||
|
@ -1,13 +0,0 @@
|
||||
#ifndef CC_ERRORHANDLER_H
|
||||
#define CC_ERRORHANDLER_H
|
||||
#include "String.h"
|
||||
/* Support methods for checking and handling errors.
|
||||
NOTE: Methods here use raw characters pointers, DO NOT apply this style elsewhere.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
void ErrorHandler_Init(void);
|
||||
void ErrorHandler_Log(const String* msg);
|
||||
void ErrorHandler_Fail(const char* raw_msg);
|
||||
CC_NOINLINE void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg);
|
||||
#endif
|
@ -56,12 +56,12 @@ static void Event_RegisterImpl(struct Event_Void* handlers, void* obj, Event_Voi
|
||||
int i;
|
||||
for (i = 0; i < handlers->Count; i++) {
|
||||
if (handlers->Handlers[i] == handler && handlers->Objs[i] == obj) {
|
||||
ErrorHandler_Fail("Attempt to register event handler that was already registered");
|
||||
Logger_Abort("Attempt to register event handler that was already registered");
|
||||
}
|
||||
}
|
||||
|
||||
if (handlers->Count == EVENT_MAX_CALLBACKS) {
|
||||
ErrorHandler_Fail("Unable to register another event handler");
|
||||
Logger_Abort("Unable to register another event handler");
|
||||
} else {
|
||||
handlers->Handlers[handlers->Count] = handler;
|
||||
handlers->Objs[handlers->Count] = obj;
|
||||
@ -85,7 +85,7 @@ static void Event_UnregisterImpl(struct Event_Void* handlers, void* obj, Event_V
|
||||
handlers->Objs[handlers->Count] = NULL;
|
||||
return;
|
||||
}
|
||||
ErrorHandler_Fail("Attempt to unregister event handler that was not registered to begin with");
|
||||
Logger_Abort("Attempt to unregister event handler that was not registered to begin with");
|
||||
}
|
||||
|
||||
void Event_RaiseVoid(struct Event_Void* handlers) {
|
||||
|
@ -64,16 +64,16 @@ void Map_LoadFrom(const String* path) {
|
||||
Game_Reset();
|
||||
|
||||
res = Stream_OpenFile(&stream, path);
|
||||
if (res) { Chat_LogError2(res, "opening", path); return; }
|
||||
if (res) { Logger_Warn2(res, "opening", path); return; }
|
||||
|
||||
importer = Map_FindImporter(path);
|
||||
if ((res = importer(&stream))) {
|
||||
World_Reset();
|
||||
Chat_LogError2(res, "decoding", path); stream.Close(&stream); return;
|
||||
Logger_Warn2(res, "decoding", path); stream.Close(&stream); return;
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", path); }
|
||||
if (res) { Logger_Warn2(res, "closing", path); }
|
||||
|
||||
World_SetNewMap(World_Blocks, World_BlocksSize, World_Width, World_Height, World_Length);
|
||||
Event_RaiseVoid(&WorldEvents_MapLoaded);
|
||||
@ -287,34 +287,34 @@ struct NbtTag {
|
||||
};
|
||||
|
||||
static uint8_t NbtTag_U8(struct NbtTag* tag) {
|
||||
if (tag->TagID != NBT_I8) ErrorHandler_Fail("Expected I8 NBT tag");
|
||||
if (tag->TagID != NBT_I8) Logger_Abort("Expected I8 NBT tag");
|
||||
return tag->Value.U8;
|
||||
}
|
||||
|
||||
static int16_t NbtTag_I16(struct NbtTag* tag) {
|
||||
if (tag->TagID != NBT_I16) ErrorHandler_Fail("Expected I16 NBT tag");
|
||||
if (tag->TagID != NBT_I16) Logger_Abort("Expected I16 NBT tag");
|
||||
return tag->Value.I16;
|
||||
}
|
||||
|
||||
static uint16_t NbtTag_U16(struct NbtTag* tag) {
|
||||
if (tag->TagID != NBT_I16) ErrorHandler_Fail("Expected I16 NBT tag");
|
||||
if (tag->TagID != NBT_I16) Logger_Abort("Expected I16 NBT tag");
|
||||
return tag->Value.U16;
|
||||
}
|
||||
|
||||
static float NbtTag_F32(struct NbtTag* tag) {
|
||||
if (tag->TagID != NBT_F32) ErrorHandler_Fail("Expected F32 NBT tag");
|
||||
if (tag->TagID != NBT_F32) Logger_Abort("Expected F32 NBT tag");
|
||||
return tag->Value.F32;
|
||||
}
|
||||
|
||||
static uint8_t* NbtTag_U8_Array(struct NbtTag* tag, int minSize) {
|
||||
if (tag->TagID != NBT_I8S) ErrorHandler_Fail("Expected I8_Array NBT tag");
|
||||
if (tag->DataSize < minSize) ErrorHandler_Fail("I8_Array NBT tag too small");
|
||||
if (tag->TagID != NBT_I8S) Logger_Abort("Expected I8_Array NBT tag");
|
||||
if (tag->DataSize < minSize) Logger_Abort("I8_Array NBT tag too small");
|
||||
|
||||
return NbtTag_IsSmall(tag) ? tag->Value.Small : tag->Value.Big;
|
||||
}
|
||||
|
||||
static String NbtTag_String(struct NbtTag* tag) {
|
||||
if (tag->TagID != NBT_STR) ErrorHandler_Fail("Expected String NBT tag");
|
||||
if (tag->TagID != NBT_STR) Logger_Abort("Expected String NBT tag");
|
||||
return tag->Value.Str.Text;
|
||||
}
|
||||
|
||||
@ -427,7 +427,7 @@ static void Cw_Callback_1(struct NbtTag* tag) {
|
||||
if (IsTag(tag, "Z")) { World_Length = NbtTag_U16(tag); return; }
|
||||
|
||||
if (IsTag(tag, "UUID")) {
|
||||
if (tag->DataSize != sizeof(World_Uuid)) ErrorHandler_Fail("Map UUID must be 16 bytes");
|
||||
if (tag->DataSize != sizeof(World_Uuid)) Logger_Abort("Map UUID must be 16 bytes");
|
||||
Mem_Copy(World_Uuid, tag->Value.Small, sizeof(World_Uuid));
|
||||
return;
|
||||
}
|
||||
@ -793,7 +793,7 @@ static ReturnCode Dat_ReadFieldData(struct Stream* stream, struct JFieldDesc* fi
|
||||
}
|
||||
|
||||
static int32_t Dat_I32(struct JFieldDesc* field) {
|
||||
if (field->Type != JFIELD_I32) ErrorHandler_Fail("Field type must be Int32");
|
||||
if (field->Type != JFIELD_I32) Logger_Abort("Field type must be Int32");
|
||||
return field->Value.I32;
|
||||
}
|
||||
|
||||
@ -834,7 +834,7 @@ ReturnCode Dat_Load(struct Stream* stream) {
|
||||
} else if (String_CaselessEqualsConst(&fieldName, "depth")) {
|
||||
World_Height = Dat_I32(field);
|
||||
} else if (String_CaselessEqualsConst(&fieldName, "blocks")) {
|
||||
if (field->Type != JFIELD_ARRAY) ErrorHandler_Fail("Blocks field must be Array");
|
||||
if (field->Type != JFIELD_ARRAY) Logger_Abort("Blocks field must be Array");
|
||||
World_Blocks = field->Value.Array.Ptr;
|
||||
#ifdef EXTENDED_BLOCKS
|
||||
World_Blocks2 = World_Blocks;
|
||||
|
37
src/Game.c
37
src/Game.c
@ -12,7 +12,7 @@
|
||||
#include "Window.h"
|
||||
#include "Event.h"
|
||||
#include "Utils.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Entity.h"
|
||||
#include "Chat.h"
|
||||
#include "Drawer2D.h"
|
||||
@ -85,7 +85,7 @@ int ScheduledTask_Add(double interval, ScheduledTaskCallback callback) {
|
||||
task.Callback = callback;
|
||||
|
||||
if (Game_TasksCount == Array_Elems(Game_Tasks)) {
|
||||
ErrorHandler_Fail("ScheduledTask_Add - hit max count");
|
||||
Logger_Abort("ScheduledTask_Add - hit max count");
|
||||
}
|
||||
Game_Tasks[Game_TasksCount++] = task;
|
||||
return Game_TasksCount - 1;
|
||||
@ -232,7 +232,7 @@ bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String*
|
||||
ReturnCode res;
|
||||
|
||||
res = Png_Decode(&bmp, src);
|
||||
if (res) { Chat_LogError2(res, "decoding", file); }
|
||||
if (res) { Logger_Warn2(res, "decoding", file); }
|
||||
|
||||
success = !res && Game_ValidateBitmap(file, &bmp);
|
||||
if (success) {
|
||||
@ -305,7 +305,7 @@ static void Game_TextureChangedCore(void* obj, struct Stream* src, const String*
|
||||
res = Png_Decode(&bmp, src);
|
||||
|
||||
if (res) {
|
||||
Chat_LogError2(res, "decoding", name);
|
||||
Logger_Warn2(res, "decoding", name);
|
||||
Mem_Free(bmp.Scan0);
|
||||
} else if (!Game_ChangeTerrainAtlas(&bmp)) {
|
||||
Mem_Free(bmp.Scan0);
|
||||
@ -314,7 +314,7 @@ static void Game_TextureChangedCore(void* obj, struct Stream* src, const String*
|
||||
}
|
||||
|
||||
static void Game_OnLowVRAMDetected(void* obj) {
|
||||
if (Game_UserViewDistance <= 16) ErrorHandler_Fail("Out of video memory!");
|
||||
if (Game_UserViewDistance <= 16) Logger_Abort("Out of video memory!");
|
||||
Game_UserViewDistance /= 2;
|
||||
Game_UserViewDistance = max(16, Game_UserViewDistance);
|
||||
|
||||
@ -323,6 +323,13 @@ static void Game_OnLowVRAMDetected(void* obj) {
|
||||
Chat_AddRaw("&cOut of VRAM! Halving view distance..");
|
||||
}
|
||||
|
||||
static void Game_Warn(ReturnCode result, const char* place) {
|
||||
Chat_Add4("&cError %h when %c", &result, place, NULL, NULL);
|
||||
}
|
||||
static void Game_Warn2(ReturnCode result, const char* place, const String* path) {
|
||||
Chat_Add4("&cError %h when %c '%s'", &result, place, path, NULL);
|
||||
}
|
||||
|
||||
static void Game_ExtractInitialTexturePack(void) {
|
||||
String texPack; char texPackBuffer[STRING_SIZE];
|
||||
|
||||
@ -383,12 +390,12 @@ static void Game_LoadPlugin(const String* filename, void* obj) {
|
||||
/* ignore classicalsharp's accepted.txt */
|
||||
if (String_CaselessEnds(filename, &txt)) return;
|
||||
res = Platform_LoadLibrary(filename, &lib);
|
||||
if (res) { Chat_LogError2(res, "loading plugin", filename); return; }
|
||||
if (res) { Logger_Warn2(res, "loading plugin", filename); return; }
|
||||
|
||||
res = Platform_GetSymbol(lib, "Plugin_ApiVersion", &verSymbol);
|
||||
if (res) { Chat_LogError2(res, "getting plugin version", filename); return; }
|
||||
if (res) { Logger_Warn2(res, "getting version of", filename); return; }
|
||||
res = Platform_GetSymbol(lib, "Plugin_Component", &compSymbol);
|
||||
if (res) { Chat_LogError2(res, "initing plugin", filename); return; }
|
||||
if (res) { Logger_Warn2(res, "initing", filename); return; }
|
||||
|
||||
ver = *((int*)verSymbol);
|
||||
if (ver < GAME_API_VER) {
|
||||
@ -407,7 +414,7 @@ static void Game_LoadPlugins(void) {
|
||||
ReturnCode res;
|
||||
|
||||
res = Directory_Enum(&dir, NULL, Game_LoadPlugin);
|
||||
if (res) Chat_LogError(res, "enumerating plugins directory");
|
||||
if (res) Logger_Warn(res, "enumerating plugins directory");
|
||||
}
|
||||
|
||||
void Game_Free(void* obj);
|
||||
@ -415,6 +422,9 @@ static void Game_Load(void) {
|
||||
String title; char titleBuffer[STRING_SIZE];
|
||||
struct IGameComponent* comp;
|
||||
|
||||
Logger_Warn = Game_Warn;
|
||||
Logger_Warn2 = Game_Warn2;
|
||||
|
||||
Game_ViewDistance = 512;
|
||||
Game_MaxViewDistance = 32768;
|
||||
Game_UserViewDistance = 512;
|
||||
@ -610,15 +620,15 @@ void Game_TakeScreenshot(void) {
|
||||
String_Format1(&path, "screenshots/%s", &filename);
|
||||
|
||||
res = Stream_CreateFile(&stream, &path);
|
||||
if (res) { Chat_LogError2(res, "creating", &path); return; }
|
||||
if (res) { Logger_Warn2(res, "creating", &path); return; }
|
||||
|
||||
res = Gfx_TakeScreenshot(&stream, Game_Width, Game_Height);
|
||||
if (res) {
|
||||
Chat_LogError2(res, "saving to", &path); stream.Close(&stream); return;
|
||||
Logger_Warn2(res, "saving to", &path); stream.Close(&stream); return;
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", &path); return; }
|
||||
if (res) { Logger_Warn2(res, "closing", &path); return; }
|
||||
|
||||
Chat_Add1("&eTaken screenshot as: %s", &filename);
|
||||
}
|
||||
@ -684,6 +694,9 @@ void Game_Free(void* obj) {
|
||||
for (comp = comps_head; comp; comp = comp->Next) {
|
||||
if (comp->Free) comp->Free();
|
||||
}
|
||||
|
||||
Logger_Warn = Logger_DialogWarn;
|
||||
Logger_Warn2 = Logger_DialogWarn2;
|
||||
Gfx_Free();
|
||||
|
||||
if (!Options_HasAnyChanged()) return;
|
||||
|
@ -284,9 +284,9 @@ static DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
static D3DFORMAT d3d9_viewFormat, d3d9_depthFormat;
|
||||
|
||||
#define D3D9_SetRenderState(state, value, name) \
|
||||
ReturnCode res = IDirect3DDevice9_SetRenderState(device, state, value); if (res) ErrorHandler_Fail2(res, name);
|
||||
ReturnCode res = IDirect3DDevice9_SetRenderState(device, state, value); if (res) Logger_Abort2(res, name);
|
||||
#define D3D9_SetRenderState2(state, value, name) \
|
||||
res = IDirect3DDevice9_SetRenderState(device, state, value); if (res) ErrorHandler_Fail2(res, name);
|
||||
res = IDirect3DDevice9_SetRenderState(device, state, value); if (res) Logger_Abort2(res, name);
|
||||
|
||||
static void D3D9_SetDefaultRenderStates(void);
|
||||
static void D3D9_RestoreRenderStates(void);
|
||||
@ -327,7 +327,7 @@ static void D3D9_FindCompatibleFormat(void) {
|
||||
res = IDirect3D9_CheckDeviceType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9_viewFormat, d3d9_viewFormat, true);
|
||||
if (!res) break;
|
||||
}
|
||||
if (i == count) ErrorHandler_Fail("Unable to create a back buffer with sufficient precision.");
|
||||
if (i == count) Logger_Abort("Unable to create a back buffer with sufficient precision.");
|
||||
|
||||
count = Array_Elems(depthFormats);
|
||||
for (i = 0; i < count; i++) {
|
||||
@ -335,7 +335,7 @@ static void D3D9_FindCompatibleFormat(void) {
|
||||
res = IDirect3D9_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9_viewFormat, d3d9_viewFormat, d3d9_depthFormat);
|
||||
if (!res) break;
|
||||
}
|
||||
if (i == count) ErrorHandler_Fail("Unable to create a depth buffer with sufficient precision.");
|
||||
if (i == count) Logger_Abort("Unable to create a depth buffer with sufficient precision.");
|
||||
}
|
||||
|
||||
static void D3D9_FillPresentArgs(int width, int height, D3DPRESENT_PARAMETERS* args) {
|
||||
@ -383,11 +383,11 @@ void Gfx_Init(void) {
|
||||
createFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
||||
res = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, createFlags, &args, &device);
|
||||
}
|
||||
if (res) ErrorHandler_Fail2(res, "Creating Direct3D9 device");
|
||||
if (res) Logger_Abort2(res, "Creating Direct3D9 device");
|
||||
|
||||
D3DCAPS9 caps;
|
||||
res = IDirect3DDevice9_GetDeviceCaps(device, &caps);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting Direct3D9 capabilities");
|
||||
if (res) Logger_Abort2(res, "Getting Direct3D9 capabilities");
|
||||
|
||||
Gfx_MaxTexWidth = caps.MaxTextureWidth;
|
||||
Gfx_MaxTexHeight = caps.MaxTextureHeight;
|
||||
@ -410,13 +410,13 @@ void Gfx_Free(void) {
|
||||
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, int lvl) {
|
||||
D3DLOCKED_RECT rect;
|
||||
ReturnCode res = IDirect3DTexture9_LockRect(texture, lvl, &rect, NULL, 0);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetTextureData - Lock");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetTextureData - Lock");
|
||||
|
||||
uint32_t size = Bitmap_DataSize(bmp->Width, bmp->Height);
|
||||
Mem_Copy(rect.pBits, bmp->Scan0, size);
|
||||
|
||||
res = IDirect3DTexture9_UnlockRect(texture, lvl);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetTextureData - Unlock");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetTextureData - Unlock");
|
||||
}
|
||||
|
||||
static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp, int lvl) {
|
||||
@ -426,7 +426,7 @@ static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, Bi
|
||||
|
||||
D3DLOCKED_RECT rect;
|
||||
ReturnCode res = IDirect3DTexture9_LockRect(texture, lvl, &rect, &part, 0);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetTexturePartData - Lock");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetTexturePartData - Lock");
|
||||
|
||||
/* We need to copy scanline by scanline, as generally rect.stride != data.stride */
|
||||
uint8_t* src = (uint8_t*)bmp->Scan0;
|
||||
@ -441,7 +441,7 @@ static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, Bi
|
||||
}
|
||||
|
||||
res = IDirect3DTexture9_UnlockRect(texture, lvl);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetTexturePartData - Unlock");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetTexturePartData - Unlock");
|
||||
}
|
||||
|
||||
static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp, bool partial) {
|
||||
@ -480,13 +480,13 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
|
||||
int levels = 1 + (mipmaps ? mipmapsLevels : 0);
|
||||
|
||||
if (!Math_IsPowOf2(bmp->Width) || !Math_IsPowOf2(bmp->Height)) {
|
||||
ErrorHandler_Fail("Textures must have power of two dimensions");
|
||||
Logger_Abort("Textures must have power of two dimensions");
|
||||
}
|
||||
|
||||
if (managedPool) {
|
||||
res = IDirect3DDevice9_CreateTexture(device, bmp->Width, bmp->Height, levels,
|
||||
0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateTexture");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateTexture");
|
||||
|
||||
D3D9_SetTextureData(tex, bmp, 0);
|
||||
if (mipmaps) D3D9_DoMipmaps(tex, 0, 0, bmp, false);
|
||||
@ -494,17 +494,17 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
|
||||
IDirect3DTexture9* sys;
|
||||
res = IDirect3DDevice9_CreateTexture(device, bmp->Width, bmp->Height, levels,
|
||||
0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &sys, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateTexture - SystemMem");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateTexture - SystemMem");
|
||||
|
||||
D3D9_SetTextureData(sys, bmp, 0);
|
||||
if (mipmaps) D3D9_DoMipmaps(sys, 0, 0, bmp, false);
|
||||
|
||||
res = IDirect3DDevice9_CreateTexture(device, bmp->Width, bmp->Height, levels,
|
||||
0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateTexture - GPU");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateTexture - GPU");
|
||||
|
||||
res = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9*)sys, (IDirect3DBaseTexture9*)tex);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateTexture - Update");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateTexture - Update");
|
||||
D3D9_FreeResource(&sys);
|
||||
}
|
||||
return tex;
|
||||
@ -518,7 +518,7 @@ void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, bool
|
||||
|
||||
void Gfx_BindTexture(GfxResourceID texId) {
|
||||
ReturnCode res = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9*)texId);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_BindTexture");
|
||||
if (res) Logger_Abort2(res, "D3D9_BindTexture");
|
||||
}
|
||||
|
||||
void Gfx_DeleteTexture(GfxResourceID* texId) { D3D9_FreeResource(texId); }
|
||||
@ -526,20 +526,20 @@ void Gfx_DeleteTexture(GfxResourceID* texId) { D3D9_FreeResource(texId); }
|
||||
void Gfx_SetTexturing(bool enabled) {
|
||||
if (enabled) return;
|
||||
ReturnCode res = IDirect3DDevice9_SetTexture(device, 0, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetTexturing");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetTexturing");
|
||||
}
|
||||
|
||||
void Gfx_EnableMipmaps(void) {
|
||||
if (Gfx_Mipmaps) {
|
||||
ReturnCode res = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_EnableMipmaps");
|
||||
if (res) Logger_Abort2(res, "D3D9_EnableMipmaps");
|
||||
}
|
||||
}
|
||||
|
||||
void Gfx_DisableMipmaps(void) {
|
||||
if (Gfx_Mipmaps) {
|
||||
ReturnCode res = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_DisableMipmaps");
|
||||
if (res) Logger_Abort2(res, "D3D9_DisableMipmaps");
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,7 +642,7 @@ void Gfx_SetAlphaBlendFunc(BlendFunc srcFunc, BlendFunc dstFunc) {
|
||||
void Gfx_SetAlphaArgBlend(bool enabled) {
|
||||
D3DTEXTUREOP op = enabled ? D3DTOP_MODULATE : D3DTOP_SELECTARG1;
|
||||
ReturnCode res = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, op);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetAlphaArgBlend");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetAlphaArgBlend");
|
||||
}
|
||||
|
||||
void Gfx_ClearCol(PackedCol col) { d3d9_clearCol.C = col; }
|
||||
@ -707,7 +707,7 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
|
||||
IDirect3DVertexBuffer9* vbuffer;
|
||||
ReturnCode res = IDirect3DDevice9_CreateVertexBuffer(device, size, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
|
||||
d3d9_formatMappings[fmt], D3DPOOL_DEFAULT, &vbuffer, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateDynamicVb");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateDynamicVb");
|
||||
|
||||
return vbuffer;
|
||||
}
|
||||
@ -715,11 +715,11 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
|
||||
static void D3D9_SetVbData(IDirect3DVertexBuffer9* buffer, void* data, int size, const char* lockMsg, const char* unlockMsg, int lockFlags) {
|
||||
void* dst = NULL;
|
||||
ReturnCode res = IDirect3DVertexBuffer9_Lock(buffer, 0, size, &dst, lockFlags);
|
||||
if (res) ErrorHandler_Fail2(res, lockMsg);
|
||||
if (res) Logger_Abort2(res, lockMsg);
|
||||
|
||||
Mem_Copy(dst, data, size);
|
||||
res = IDirect3DVertexBuffer9_Unlock(buffer);
|
||||
if (res) ErrorHandler_Fail2(res, unlockMsg);
|
||||
if (res) Logger_Abort2(res, unlockMsg);
|
||||
}
|
||||
|
||||
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
||||
@ -732,7 +732,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
||||
d3d9_formatMappings[fmt], D3DPOOL_DEFAULT, &vbuffer, NULL);
|
||||
if (!res) break;
|
||||
|
||||
if (res != D3DERR_OUTOFVIDEOMEMORY) ErrorHandler_Fail2(res, "D3D9_CreateVb");
|
||||
if (res != D3DERR_OUTOFVIDEOMEMORY) Logger_Abort2(res, "D3D9_CreateVb");
|
||||
Event_RaiseVoid(&GfxEvents_LowVRAMDetected);
|
||||
}
|
||||
|
||||
@ -743,18 +743,18 @@ GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
||||
static void D3D9_SetIbData(IDirect3DIndexBuffer9* buffer, void* data, int size) {
|
||||
void* dst = NULL;
|
||||
ReturnCode res = IDirect3DIndexBuffer9_Lock(buffer, 0, size, &dst, 0);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateIb - Lock");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateIb - Lock");
|
||||
|
||||
Mem_Copy(dst, data, size);
|
||||
res = IDirect3DIndexBuffer9_Unlock(buffer);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateIb - Unlock");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateIb - Unlock");
|
||||
}
|
||||
|
||||
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
||||
int size = indicesCount * 2;
|
||||
IDirect3DIndexBuffer9* ibuffer;
|
||||
ReturnCode res = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateIb");
|
||||
if (res) Logger_Abort2(res, "D3D9_CreateIb");
|
||||
|
||||
D3D9_SetIbData(ibuffer, indices, size);
|
||||
return ibuffer;
|
||||
@ -763,13 +763,13 @@ GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
||||
void Gfx_BindVb(GfxResourceID vb) {
|
||||
IDirect3DVertexBuffer9* vbuffer = (IDirect3DVertexBuffer9*)vb;
|
||||
ReturnCode res = IDirect3DDevice9_SetStreamSource(device, 0, vbuffer, 0, gfx_batchStride);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_BindVb");
|
||||
if (res) Logger_Abort2(res, "D3D9_BindVb");
|
||||
}
|
||||
|
||||
void Gfx_BindIb(GfxResourceID ib) {
|
||||
IDirect3DIndexBuffer9* ibuffer = (IDirect3DIndexBuffer9*)ib;
|
||||
ReturnCode res = IDirect3DDevice9_SetIndices(device, ibuffer);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_BindIb");
|
||||
if (res) Logger_Abort2(res, "D3D9_BindIb");
|
||||
}
|
||||
|
||||
void Gfx_DeleteVb(GfxResourceID* vb) { D3D9_FreeResource(vb); }
|
||||
@ -780,7 +780,7 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
||||
gfx_batchFormat = fmt;
|
||||
|
||||
ReturnCode res = IDirect3DDevice9_SetFVF(device, d3d9_formatMappings[fmt]);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetBatchFormat");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetBatchFormat");
|
||||
gfx_batchStride = gfx_strideSizes[fmt];
|
||||
}
|
||||
|
||||
@ -790,30 +790,30 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
|
||||
D3D9_SetVbData(vbuffer, vertices, size, "D3D9_SetDynamicVbData - Lock", "D3D9_SetDynamicVbData - Unlock", D3DLOCK_DISCARD);
|
||||
|
||||
ReturnCode res = IDirect3DDevice9_SetStreamSource(device, 0, vbuffer, 0, gfx_batchStride);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_SetDynamicVbData - Bind");
|
||||
if (res) Logger_Abort2(res, "D3D9_SetDynamicVbData - Bind");
|
||||
}
|
||||
|
||||
void Gfx_DrawVb_Lines(int verticesCount) {
|
||||
ReturnCode res = IDirect3DDevice9_DrawPrimitive(device, D3DPT_LINELIST, 0, verticesCount >> 1);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_DrawVb_Lines");
|
||||
if (res) Logger_Abort2(res, "D3D9_DrawVb_Lines");
|
||||
}
|
||||
|
||||
void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
||||
ReturnCode res = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
|
||||
0, 0, verticesCount, 0, verticesCount >> 1);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_DrawVb_IndexedTris");
|
||||
if (res) Logger_Abort2(res, "D3D9_DrawVb_IndexedTris");
|
||||
}
|
||||
|
||||
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
|
||||
ReturnCode res = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
|
||||
startVertex, 0, verticesCount, 0, verticesCount >> 1);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_DrawVb_IndexedTris");
|
||||
if (res) Logger_Abort2(res, "D3D9_DrawVb_IndexedTris");
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
ReturnCode res = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
|
||||
startVertex, 0, verticesCount, 0, verticesCount >> 1);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_DrawIndexedVb_TrisT2fC4b");
|
||||
if (res) Logger_Abort2(res, "D3D9_DrawIndexedVb_TrisT2fC4b");
|
||||
}
|
||||
|
||||
|
||||
@ -831,7 +831,7 @@ void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix) {
|
||||
|
||||
if (Gfx_LostContext) return;
|
||||
res = IDirect3DDevice9_SetTransform(device, matrix_modes[type], matrix);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_LoadMatrix");
|
||||
if (res) Logger_Abort2(res, "D3D9_LoadMatrix");
|
||||
}
|
||||
|
||||
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||
@ -842,7 +842,7 @@ void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||
|
||||
if (Gfx_LostContext) return;
|
||||
res = IDirect3DDevice9_SetTransform(device, matrix_modes[type], &Matrix_Identity);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_LoadIdentityMatrix");
|
||||
if (res) Logger_Abort2(res, "D3D9_LoadIdentityMatrix");
|
||||
}
|
||||
|
||||
#define d3d9_zN -10000.0f
|
||||
@ -901,14 +901,14 @@ void Gfx_BeginFrame(void) { IDirect3DDevice9_BeginScene(device); }
|
||||
void Gfx_Clear(void) {
|
||||
DWORD flags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER;
|
||||
ReturnCode res = IDirect3DDevice9_Clear(device, 0, NULL, flags, d3d9_clearCol.Raw, 1.0f, 0);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_Clear");
|
||||
if (res) Logger_Abort2(res, "D3D9_Clear");
|
||||
}
|
||||
|
||||
void Gfx_EndFrame(void) {
|
||||
IDirect3DDevice9_EndScene(device);
|
||||
ReturnCode res = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
|
||||
if (!res) return;
|
||||
if (res != D3DERR_DEVICELOST) ErrorHandler_Fail2(res, "D3D9_EndFrame");
|
||||
if (res != D3DERR_DEVICELOST) Logger_Abort2(res, "D3D9_EndFrame");
|
||||
|
||||
/* TODO: Make sure this actually works on all graphics cards.*/
|
||||
Gfx_LoseContext(" (Direct3D9 device lost)");
|
||||
@ -1043,7 +1043,7 @@ static void GL_CheckVboSupport(void) {
|
||||
glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubDataARB");
|
||||
#endif
|
||||
} else {
|
||||
ErrorHandler_Fail("Only OpenGL 1.1 supported.\r\n\r\n" \
|
||||
Logger_Abort("Only OpenGL 1.1 supported.\r\n\r\n" \
|
||||
"Compile the game with CC_BUILD_GL11, or ask on the classicube forums for it");
|
||||
}
|
||||
}
|
||||
@ -1114,7 +1114,7 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
if (!Math_IsPowOf2(bmp->Width) || !Math_IsPowOf2(bmp->Height)) {
|
||||
ErrorHandler_Fail("Textures must have power of two dimensions");
|
||||
Logger_Abort("Textures must have power of two dimensions");
|
||||
}
|
||||
|
||||
if (mipmaps) {
|
||||
|
@ -193,7 +193,7 @@ void Gui_RefreshHud(void) { Elem_Recreate(Gui_HUD); }
|
||||
void Gui_ShowOverlay(struct Screen* overlay, bool atFront) {
|
||||
int i;
|
||||
if (Gui_OverlaysCount == GUI_MAX_OVERLAYS) {
|
||||
ErrorHandler_Fail("Gui_ShowOverlay - hit max count");
|
||||
Logger_Abort("Gui_ShowOverlay - hit max count");
|
||||
}
|
||||
|
||||
if (atFront) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Stream.h"
|
||||
#include "Funcs.h"
|
||||
#include "Resources.h"
|
||||
#include "Logger.h"
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------Screen base-----------------------------------------------------*
|
||||
@ -1457,7 +1458,7 @@ static void UpdatesScreen_Init(struct LScreen* s_) {
|
||||
|
||||
res = File_GetModifiedTime(&exeName, &buildTime);
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "getting build time");
|
||||
Logger_Warn(res, "getting build time");
|
||||
} else {
|
||||
UpdatesScreen_Format(&s->LblYour, "Your build: ", buildTime);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Launcher.h"
|
||||
#include "Platform.h"
|
||||
#include "Stream.h"
|
||||
#include "Logger.h"
|
||||
|
||||
/*########################################################################################################################*
|
||||
*----------------------------------------------------------JSON-----------------------------------------------------------*
|
||||
@ -457,13 +458,13 @@ static void FetchUpdateTask_Handle(uint8_t* data, uint32_t len) {
|
||||
ReturnCode res;
|
||||
|
||||
res = Stream_WriteAllTo(&path, data, len);
|
||||
if (res) { Launcher_ShowError(res, "saving update"); return; }
|
||||
if (res) { Logger_Warn(res, "saving update"); return; }
|
||||
|
||||
res = File_SetModifiedTime(&path, FetchUpdateTask.Timestamp);
|
||||
if (res) Launcher_ShowError(res, "setting update time");
|
||||
if (res) Logger_Warn(res, "setting update time");
|
||||
|
||||
res = Platform_MarkExecutable(&path);
|
||||
if (res) Launcher_ShowError(res, "making update executable");
|
||||
if (res) Logger_Warn(res, "making update executable");
|
||||
}
|
||||
|
||||
void FetchUpdateTask_Run(bool release, bool d3d9) {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "AsyncDownloader.h"
|
||||
#include "ExtMath.h"
|
||||
#include "Funcs.h"
|
||||
#include "Logger.h"
|
||||
|
||||
struct LScreen* Launcher_Screen;
|
||||
Rect2D Launcher_Dirty;
|
||||
@ -27,16 +28,6 @@ static FontDesc logoFont;
|
||||
bool Launcher_ShouldExit, Launcher_ShouldUpdate;
|
||||
static void Launcher_ApplyUpdate(void);
|
||||
|
||||
|
||||
void Launcher_ShowError(ReturnCode res, const char* place) {
|
||||
String msg; char msgBuffer[STRING_SIZE * 2];
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
|
||||
String_Format2(&msg, "Error %h when %c", &res, place);
|
||||
msg.buffer[msg.length] = '\0';
|
||||
Window_ShowDialog("Error", msg.buffer);
|
||||
}
|
||||
|
||||
void Launcher_SetScreen(struct LScreen* screen) {
|
||||
if (Launcher_Screen) Launcher_Screen->Free(Launcher_Screen);
|
||||
Launcher_Screen = screen;
|
||||
@ -83,10 +74,10 @@ bool Launcher_ConnectToServer(const String* hash) {
|
||||
Launcher_StartFromInfo(&FetchServerTask.Server);
|
||||
return true;
|
||||
} else if (FetchServerTask.Base.Res) {
|
||||
Launcher_ShowError(FetchServerTask.Base.Res, "fetching server info");
|
||||
Logger_Warn(FetchServerTask.Base.Res, "fetching server info");
|
||||
} else if (FetchServerTask.Base.Status != 200) {
|
||||
/* TODO: Use a better dialog message.. */
|
||||
Launcher_ShowError(FetchServerTask.Base.Status, "fetching server info");
|
||||
Logger_Warn(FetchServerTask.Base.Status, "fetching server info");
|
||||
} else {
|
||||
Window_ShowDialog("Failed to connect", "No server has that hash");
|
||||
}
|
||||
@ -377,7 +368,7 @@ static ReturnCode Launcher_ProcessZipEntry(const String* path, struct Stream* da
|
||||
res = Png_Decode(&fontBmp, data);
|
||||
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "decoding default.png"); return res;
|
||||
Logger_Warn(res, "decoding default.png"); return res;
|
||||
} else {
|
||||
Drawer2D_SetFontBitmap(&fontBmp);
|
||||
useBitmappedFont = !Options_GetBool(OPT_USE_CHAT_FONT, false);
|
||||
@ -387,7 +378,7 @@ static ReturnCode Launcher_ProcessZipEntry(const String* path, struct Stream* da
|
||||
res = Png_Decode(&bmp, data);
|
||||
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "decoding terrain.png"); return res;
|
||||
Logger_Warn(res, "decoding terrain.png"); return res;
|
||||
} else {
|
||||
Launcher_LoadTextures(&bmp);
|
||||
}
|
||||
@ -402,7 +393,7 @@ static void Launcher_ExtractTexturePack(const String* path) {
|
||||
|
||||
res = Stream_OpenFile(&stream, path);
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "opening texture pack"); return;
|
||||
Logger_Warn(res, "opening texture pack"); return;
|
||||
}
|
||||
|
||||
Zip_Init(&state, &stream);
|
||||
@ -411,7 +402,7 @@ static void Launcher_ExtractTexturePack(const String* path) {
|
||||
res = Zip_Extract(&state);
|
||||
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "extracting texture pack");
|
||||
Logger_Warn(res, "extracting texture pack");
|
||||
}
|
||||
stream.Close(&stream);
|
||||
}
|
||||
@ -558,7 +549,7 @@ bool Launcher_StartGame(const String* user, const String* mppass, const String*
|
||||
#endif
|
||||
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "starting game");
|
||||
Logger_Warn(res, "starting game");
|
||||
Launcher_ShouldExit = false;
|
||||
return false;
|
||||
}
|
||||
@ -618,12 +609,12 @@ static void Launcher_ApplyUpdate(void) {
|
||||
|
||||
/* Can't use WriteLine, want \n as actual newline not code page 437 */
|
||||
res = Stream_WriteAllTo(&scriptPath, UPDATE_SCRIPT, sizeof(UPDATE_SCRIPT) - 1);
|
||||
if (res) { Launcher_ShowError(res, "saving update script"); return; }
|
||||
if (res) { Logger_Warn(res, "saving update script"); return; }
|
||||
|
||||
res = Platform_MarkExecutable(&scriptPath);
|
||||
if (res) Launcher_ShowError(res, "making update script executable");
|
||||
if (res) Logger_Warn(res, "making update script executable");
|
||||
|
||||
/* TODO: (open -a Terminal ", '"' + path + '"'); on OSX */
|
||||
res = Platform_StartProcess(&scriptName, &scriptArgs);
|
||||
if (res) { Launcher_ShowError(res, "starting update script"); return; }
|
||||
if (res) { Logger_Warn(res, "starting update script"); return; }
|
||||
}
|
||||
|
@ -72,9 +72,6 @@ void Launcher_SetScreen(struct LScreen* screen);
|
||||
bool Launcher_ConnectToServer(const String* hash);
|
||||
/* Launcher main loop. */
|
||||
void Launcher_Run(void);
|
||||
|
||||
/* Shows a message box for an error. */
|
||||
void Launcher_ShowError(ReturnCode res, const char* place);
|
||||
/* Starts the game from the given arguments. */
|
||||
bool Launcher_StartGame(const String* user, const String* mppass, const String* ip, const String* port, const String* server);
|
||||
#endif
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Platform.h"
|
||||
#include "Chat.h"
|
||||
#include "Window.h"
|
||||
#include "Funcs.h"
|
||||
#include "Stream.h"
|
||||
|
||||
static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void* ctx);
|
||||
static void ErrorHandler_DumpCommon(String* str, void* ctx);
|
||||
static void ErrorHandler_DumpRegisters(void* ctx);
|
||||
static void Logger_AbortCommon(ReturnCode result, const char* raw_msg, void* ctx);
|
||||
static void Logger_DumpCommon(String* str, void* ctx);
|
||||
static void Logger_DumpRegisters(void* ctx);
|
||||
|
||||
#ifdef CC_BUILD_WIN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@ -24,7 +24,7 @@ struct SymbolAndName { IMAGEHLP_SYMBOL Symbol; char Name[256]; };
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Info dumping------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static int ErrorHandler_GetFrames(CONTEXT* ctx, struct StackPointers* pointers, int max) {
|
||||
static int Logger_GetFrames(CONTEXT* ctx, struct StackPointers* pointers, int max) {
|
||||
STACKFRAME frame = { 0 };
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Mode = AddrModeFlat;
|
||||
@ -68,7 +68,7 @@ static int ErrorHandler_GetFrames(CONTEXT* ctx, struct StackPointers* pointers,
|
||||
return count;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK ErrorHandler_DumpModule(const char* name, ULONG_PTR base, ULONG size, void* ctx) {
|
||||
static BOOL CALLBACK Logger_DumpModule(const char* name, ULONG_PTR base, ULONG size, void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 4];
|
||||
uintptr_t beg, end;
|
||||
|
||||
@ -76,18 +76,18 @@ static BOOL CALLBACK ErrorHandler_DumpModule(const char* name, ULONG_PTR base, U
|
||||
String_InitArray(str, strBuffer);
|
||||
|
||||
String_Format3(&str, "%c = %x-%x\r\n", name, &beg, &end);
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ErrorHandler_Backtrace(String* backtrace, void* ctx) {
|
||||
static void Logger_Backtrace(String* backtrace, void* ctx) {
|
||||
struct SymbolAndName sym = { 0 };
|
||||
sym.Symbol.MaxNameLength = 255;
|
||||
sym.Symbol.SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
|
||||
|
||||
HANDLE process = GetCurrentProcess();
|
||||
struct StackPointers pointers[40];
|
||||
int i, frames = ErrorHandler_GetFrames((CONTEXT*)ctx, pointers, 40);
|
||||
int i, frames = Logger_GetFrames((CONTEXT*)ctx, pointers, 40);
|
||||
|
||||
for (i = 0; i < frames; i++) {
|
||||
int number = i + 1;
|
||||
@ -120,25 +120,25 @@ static void ErrorHandler_Backtrace(String* backtrace, void* ctx) {
|
||||
if (SymGetModuleInfo(process, addr, &module)) {
|
||||
String_Format2(&str, " in module %c (%c)\r\n", module.ModuleName, module.ImageName);
|
||||
}
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
String_AppendConst(backtrace, "\r\n");
|
||||
}
|
||||
|
||||
static void ErrorHandler_DumpCommon(String* str, void* ctx) {
|
||||
static void Logger_DumpCommon(String* str, void* ctx) {
|
||||
const static String backtrace = String_FromConst("-- backtrace --\r\n");
|
||||
const static String modules = String_FromConst("-- modules --\r\n");
|
||||
HANDLE process = GetCurrentProcess();
|
||||
|
||||
SymInitialize(process, NULL, TRUE);
|
||||
ErrorHandler_Log(&backtrace);
|
||||
ErrorHandler_Backtrace(str, ctx);
|
||||
Logger_Log(&backtrace);
|
||||
Logger_Backtrace(str, ctx);
|
||||
|
||||
ErrorHandler_Log(&modules);
|
||||
EnumerateLoadedModules(process, ErrorHandler_DumpModule, NULL);
|
||||
Logger_Log(&modules);
|
||||
EnumerateLoadedModules(process, Logger_DumpModule, NULL);
|
||||
}
|
||||
|
||||
static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 8];
|
||||
CONTEXT* r;
|
||||
if (!ctx) return;
|
||||
@ -173,14 +173,14 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Error handling-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) {
|
||||
static LONG WINAPI Logger_UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) {
|
||||
String msg; char msgBuffer[STRING_SIZE * 2 + 1];
|
||||
uint32_t code;
|
||||
uintptr_t addr;
|
||||
@ -192,20 +192,20 @@ static LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInf
|
||||
String_Format2(&msg, "Unhandled exception 0x%h at 0x%x", &code, &addr);
|
||||
msg.buffer[msg.length] = '\0';
|
||||
|
||||
ErrorHandler_DumpRegisters(pInfo->ContextRecord);
|
||||
ErrorHandler_FailCommon(0, msg.buffer, pInfo->ContextRecord);
|
||||
Logger_DumpRegisters(pInfo->ContextRecord);
|
||||
Logger_AbortCommon(0, msg.buffer, pInfo->ContextRecord);
|
||||
return EXCEPTION_EXECUTE_HANDLER; /* TODO: different flag */
|
||||
}
|
||||
|
||||
void ErrorHandler_Init(void) {
|
||||
SetUnhandledExceptionFilter(ErrorHandler_UnhandledFilter);
|
||||
void Logger_Hook(void) {
|
||||
SetUnhandledExceptionFilter(Logger_UnhandledFilter);
|
||||
}
|
||||
|
||||
/* Don't want compiler doing anything fancy with registers */
|
||||
#if _MSC_VER
|
||||
#pragma optimize ("", off)
|
||||
#endif
|
||||
void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
|
||||
void Logger_Abort2(ReturnCode result, const char* raw_msg) {
|
||||
CONTEXT ctx;
|
||||
#ifndef _M_IX86
|
||||
/* This method is guaranteed to exist on 64 bit windows */
|
||||
@ -245,7 +245,7 @@ void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
|
||||
ctx.ContextFlags = CONTEXT_CONTROL;
|
||||
#endif
|
||||
|
||||
ErrorHandler_FailCommon(result, raw_msg, &ctx);
|
||||
Logger_AbortCommon(result, raw_msg, &ctx);
|
||||
}
|
||||
#if _MSC_VER
|
||||
#pragma optimize ("", on)
|
||||
@ -263,7 +263,7 @@ void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Info dumping------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void ErrorHandler_Backtrace(String* backtrace_, void* ctx) {
|
||||
static void Logger_Backtrace(String* backtrace_, void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 5];
|
||||
void* addrs[40];
|
||||
int i, frames, num;
|
||||
@ -286,7 +286,7 @@ static void ErrorHandler_Backtrace(String* backtrace_, void* ctx) {
|
||||
}
|
||||
|
||||
String_AppendString(backtrace_, &str);
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
String_AppendConst(backtrace_, "\n");
|
||||
@ -297,7 +297,7 @@ static void ErrorHandler_Backtrace(String* backtrace_, void* ctx) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Error handling-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void ErrorHandler_SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
||||
static void Logger_SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
||||
String msg; char msgBuffer[STRING_SIZE * 2 + 1];
|
||||
int type, code;
|
||||
uintptr_t addr;
|
||||
@ -317,13 +317,13 @@ static void ErrorHandler_SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
||||
String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr);
|
||||
msg.buffer[msg.length] = '\0';
|
||||
|
||||
ErrorHandler_DumpRegisters(ctx);
|
||||
ErrorHandler_FailCommon(0, msg.buffer, ctx);
|
||||
Logger_DumpRegisters(ctx);
|
||||
Logger_AbortCommon(0, msg.buffer, ctx);
|
||||
}
|
||||
|
||||
void ErrorHandler_Init(void) {
|
||||
void Logger_Hook(void) {
|
||||
struct sigaction sa, old;
|
||||
sa.sa_sigaction = ErrorHandler_SignalHandler;
|
||||
sa.sa_sigaction = Logger_SignalHandler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
|
||||
@ -334,10 +334,10 @@ void ErrorHandler_Init(void) {
|
||||
sigaction(SIGFPE, &sa, &old);
|
||||
}
|
||||
|
||||
void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
|
||||
void Logger_Abort2(ReturnCode result, const char* raw_msg) {
|
||||
ucontext_t ctx;
|
||||
getcontext(&ctx);
|
||||
ErrorHandler_FailCommon(result, raw_msg, &ctx);
|
||||
Logger_AbortCommon(result, raw_msg, &ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -346,7 +346,7 @@ void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
|
||||
*-------------------------------------------------------Info dumping------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#if defined CC_BUILD_NIX || defined CC_BUILD_SOLARIS
|
||||
static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 8];
|
||||
mcontext_t r;
|
||||
if (!ctx) return;
|
||||
@ -370,10 +370,10 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
static void ErrorHandler_DumpMemoryMap(void) {
|
||||
static void Logger_DumpMemoryMap(void) {
|
||||
String str; char strBuffer[STRING_SIZE * 5];
|
||||
int n, fd;
|
||||
|
||||
@ -383,23 +383,23 @@ static void ErrorHandler_DumpMemoryMap(void) {
|
||||
|
||||
while ((n = read(fd, str.buffer, str.capacity)) > 0) {
|
||||
str.length = n;
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void ErrorHandler_DumpCommon(String* str, void* ctx) {
|
||||
static void Logger_DumpCommon(String* str, void* ctx) {
|
||||
const static String backtrace = String_FromConst("-- backtrace --\n");
|
||||
const static String memMap = String_FromConst("-- memory map --\n");
|
||||
|
||||
ErrorHandler_Log(&backtrace);
|
||||
ErrorHandler_Backtrace(str, ctx);
|
||||
ErrorHandler_Log(&memMap);
|
||||
ErrorHandler_DumpMemoryMap();
|
||||
Logger_Log(&backtrace);
|
||||
Logger_Backtrace(str, ctx);
|
||||
Logger_Log(&memMap);
|
||||
Logger_DumpMemoryMap();
|
||||
}
|
||||
#elif defined CC_BUILD_OSX
|
||||
static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 8];
|
||||
mcontext_t r;
|
||||
if (!ctx) return;
|
||||
@ -423,13 +423,13 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
ErrorHandler_Log(&str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
static void ErrorHandler_DumpCommon(String* str, void* ctx) {
|
||||
static void Logger_DumpCommon(String* str, void* ctx) {
|
||||
const static String backtrace = String_FromConst("-- backtrace --\n");
|
||||
ErrorHandler_Log(&backtrace);
|
||||
ErrorHandler_Backtrace(str, ctx);
|
||||
Logger_Log(&backtrace);
|
||||
Logger_Backtrace(str, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -437,11 +437,32 @@ static void ErrorHandler_DumpCommon(String* str, void* ctx) {
|
||||
/*########################################################################################################################*
|
||||
*----------------------------------------------------------Common---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void Logger_DialogWarn(ReturnCode res, const char* place) {
|
||||
String msg; char msgBuffer[STRING_SIZE * 2];
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
|
||||
String_Format2(&msg, "Error %h when %c", &res, place);
|
||||
msg.buffer[msg.length] = '\0';
|
||||
Window_ShowDialog("Error", msg.buffer);
|
||||
}
|
||||
|
||||
void Logger_DialogWarn2(ReturnCode res, const char* place, const String* path) {
|
||||
String msg; char msgBuffer[STRING_SIZE * 4];
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
|
||||
String_Format3(&msg, "Error %h when %c '%s'", &res, place, path);
|
||||
msg.buffer[msg.length] = '\0';
|
||||
Window_ShowDialog("Error", msg.buffer);
|
||||
}
|
||||
|
||||
Logger_WarnFunc Logger_Warn = Logger_DialogWarn;
|
||||
Logger_Warn2Func Logger_Warn2 = Logger_DialogWarn2;
|
||||
|
||||
static FileHandle logFile;
|
||||
static struct Stream logStream;
|
||||
static bool logOpen;
|
||||
|
||||
void ErrorHandler_Log(const String* msg) {
|
||||
void Logger_Log(const String* msg) {
|
||||
const static String path = String_FromConst("client.log");
|
||||
ReturnCode res;
|
||||
|
||||
@ -455,7 +476,7 @@ void ErrorHandler_Log(const String* msg) {
|
||||
Stream_Write(&logStream, msg->buffer, msg->length);
|
||||
}
|
||||
|
||||
static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void* ctx) {
|
||||
static void Logger_AbortCommon(ReturnCode result, const char* raw_msg, void* ctx) {
|
||||
String msg; char msgBuffer[3070 + 1];
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
|
||||
@ -468,8 +489,8 @@ static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void
|
||||
String_Format2(&msg, "%h%c", &result, Platform_NewLine);
|
||||
} else { result = 1; }
|
||||
|
||||
ErrorHandler_Log(&msg);
|
||||
ErrorHandler_DumpCommon(&msg, ctx);
|
||||
Logger_Log(&msg);
|
||||
Logger_DumpCommon(&msg, ctx);
|
||||
if (logStream.Meta.File) File_Close(logFile);
|
||||
|
||||
String_AppendConst(&msg, "Full details of the crash have been logged to 'client.log'.\n");
|
||||
@ -480,4 +501,4 @@ static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void
|
||||
Platform_Exit(result);
|
||||
}
|
||||
|
||||
void ErrorHandler_Fail(const char* raw_msg) { ErrorHandler_Fail2(0, raw_msg); }
|
||||
void Logger_Abort(const char* raw_msg) { Logger_Abort2(0, raw_msg); }
|
32
src/Logger.h
Normal file
32
src/Logger.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef CC_ERRORHANDLER_H
|
||||
#define CC_ERRORHANDLER_H
|
||||
#include "String.h"
|
||||
/* Support methods for logging errors.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
typedef void (*Logger_WarnFunc)(ReturnCode result, const char* place);
|
||||
typedef void (*Logger_Warn2Func)(ReturnCode result, const char* place, const String* path);
|
||||
|
||||
/* Informs the user about a non-fatal error, with a message of form: "Error [result] when [place] */
|
||||
/* By default this shows a message box, but changes to in-game chat when game is running. */
|
||||
extern Logger_WarnFunc Logger_Warn;
|
||||
/* Informs the user about a non-fatal error, with a message of form: "Error [result] when [place] 'path' */
|
||||
/* By default this shows a message box, but changes to in-game chat when game is running. */
|
||||
extern Logger_Warn2Func Logger_Warn2;
|
||||
|
||||
void Logger_DialogWarn(ReturnCode res, const char* place);
|
||||
void Logger_DialogWarn2(ReturnCode res, const char* place, const String* path);
|
||||
|
||||
/* Hooks the operating system's unhandled error callback/signal. */
|
||||
/* This is used to attempt to log some information about a crash due to invalid memory read, etc. */
|
||||
void Logger_Hook(void);
|
||||
/* Logs a message to client.log on disc. */
|
||||
void Logger_Log(const String* msg);
|
||||
/* Displays a message box with raw_msg body, logs state to disc, then immediately terminates/quits. */
|
||||
/* Typically used to abort due to an unrecoverable error. (e.g. out of memory) */
|
||||
void Logger_Abort(const char* raw_msg);
|
||||
/* Displays a message box with raw_msg body, logs state to disc, then immediately terminates/quits. */
|
||||
/* Typically used to abort due to an unrecoverable error. (e.g. out of memory) */
|
||||
CC_NOINLINE void Logger_Abort2(ReturnCode result, const char* raw_msg);
|
||||
#endif
|
@ -98,7 +98,7 @@ static void NotchyGen_FillOblateSpheroid(int x, int y, int z, float radius, Bloc
|
||||
#define Stack_Push(index)\
|
||||
stack[stack_size++] = index;\
|
||||
if (stack_size == 32768) {\
|
||||
ErrorHandler_Fail("NotchyGen_FloodFail - stack limit hit");\
|
||||
Logger_Abort("NotchyGen_FloodFail - stack limit hit");\
|
||||
}
|
||||
|
||||
static void NotchyGen_FloodFill(int startIndex, BlockRaw block) {
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "Deflate.h"
|
||||
#include "Stream.h"
|
||||
#include "Builder.h"
|
||||
#include "ErrorHandler.h"
|
||||
|
||||
#define MenuBase_Layout Screen_Layout struct Widget** Widgets; int WidgetsCount;
|
||||
struct Menu { MenuBase_Layout };
|
||||
@ -1244,7 +1245,7 @@ static void SaveLevelScreen_SaveMap(struct SaveLevelScreen* s, const String* pat
|
||||
ReturnCode res;
|
||||
|
||||
res = Stream_CreateFile(&stream, path);
|
||||
if (res) { Chat_LogError2(res, "creating", path); return; }
|
||||
if (res) { Logger_Warn2(res, "creating", path); return; }
|
||||
GZip_MakeStream(&compStream, &state, &stream);
|
||||
|
||||
if (String_CaselessEnds(path, &cw)) {
|
||||
@ -1255,16 +1256,16 @@ static void SaveLevelScreen_SaveMap(struct SaveLevelScreen* s, const String* pat
|
||||
|
||||
if (res) {
|
||||
stream.Close(&stream);
|
||||
Chat_LogError2(res, "encoding", path); return;
|
||||
Logger_Warn2(res, "encoding", path); return;
|
||||
}
|
||||
|
||||
if ((res = compStream.Close(&compStream))) {
|
||||
stream.Close(&stream);
|
||||
Chat_LogError2(res, "closing", path); return;
|
||||
Logger_Warn2(res, "closing", path); return;
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", path); return; }
|
||||
if (res) { Logger_Warn2(res, "closing", path); return; }
|
||||
|
||||
Chat_Add1("&eSaved map to: %s", path);
|
||||
Gui_FreeActive();
|
||||
|
@ -177,7 +177,7 @@ void Options_SetSecure(const char* opt, const String* src, const String* key) {
|
||||
}
|
||||
}
|
||||
|
||||
if (encLen > 1500) ErrorHandler_Fail("too large to base64");
|
||||
if (encLen > 1500) Logger_Abort("too large to base64");
|
||||
tmp.buffer = data;
|
||||
tmp.length = Convert_ToBase64(enc, encLen, data);
|
||||
tmp.capacity = tmp.length;
|
||||
@ -194,7 +194,7 @@ void Options_GetSecure(const char* opt, String* dst, const String* key) {
|
||||
|
||||
Options_UNSAFE_Get(opt, &raw);
|
||||
if (!raw.length || !key->length) return;
|
||||
if (raw.length > 2000) ErrorHandler_Fail("too large to base64");
|
||||
if (raw.length > 2000) Logger_Abort("too large to base64");
|
||||
dataLen = Convert_FromBase64(raw.buffer, raw.length, data);
|
||||
|
||||
if (Platform_Decrypt(data, dataLen, &dec, &decLen)) {
|
||||
|
@ -468,7 +468,7 @@ static void Classic_LevelDataChunk(uint8_t* data) {
|
||||
|
||||
if (!map_gzHeader.Done) {
|
||||
res = GZipHeader_Read(&map_part, &map_gzHeader);
|
||||
if (res && res != ERR_END_OF_STREAM) ErrorHandler_Fail2(res, "reading map data");
|
||||
if (res && res != ERR_END_OF_STREAM) Logger_Abort2(res, "reading map data");
|
||||
}
|
||||
|
||||
if (map_gzHeader.Done) {
|
||||
|
@ -186,7 +186,7 @@ static bool Picking_RayTrace(Vector3 origin, Vector3 dir, float reach, struct Pi
|
||||
RayTracer_Step(&tracer);
|
||||
}
|
||||
|
||||
ErrorHandler_Fail("Something went wrong, did over 25,000 iterations in Picking_RayTrace()");
|
||||
Logger_Abort("Something went wrong, did over 25,000 iterations in Picking_RayTrace()");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil,
|
||||
m->R = 2; m->G = 2; m->B = 1; break;
|
||||
default:
|
||||
/* mode->R = 0; mode->G = 0; mode->B = 0; */
|
||||
ErrorHandler_Fail2(bpp, "Unsupported bits per pixel"); break;
|
||||
Logger_Abort2(bpp, "Unsupported bits per pixel"); break;
|
||||
}
|
||||
}
|
||||
void GraphicsMode_MakeDefault(struct GraphicsMode* m) {
|
||||
@ -149,7 +149,7 @@ CC_NOINLINE static void Platform_AllocFailed(const char* place) {
|
||||
|
||||
String_Format1(&log, "Failed allocating memory for: %c", place);
|
||||
log.buffer[log.length] = '\0';
|
||||
ErrorHandler_Fail(log.buffer);
|
||||
Logger_Abort(log.buffer);
|
||||
}
|
||||
|
||||
#ifdef CC_BUILD_WIN
|
||||
@ -663,7 +663,7 @@ void* Thread_Start(Thread_StartFunc* func, bool detach) {
|
||||
DWORD threadID;
|
||||
void* handle = CreateThread(NULL, 0, Thread_StartCallback, func, 0, &threadID);
|
||||
if (!handle) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Creating thread");
|
||||
Logger_Abort2(GetLastError(), "Creating thread");
|
||||
}
|
||||
|
||||
if (detach) Thread_Detach(handle);
|
||||
@ -672,7 +672,7 @@ void* Thread_Start(Thread_StartFunc* func, bool detach) {
|
||||
|
||||
void Thread_Detach(void* handle) {
|
||||
if (!CloseHandle((HANDLE)handle)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Freeing thread handle");
|
||||
Logger_Abort2(GetLastError(), "Freeing thread handle");
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,7 +683,7 @@ void Thread_Join(void* handle) {
|
||||
|
||||
static CRITICAL_SECTION mutexList[3]; int mutexIndex;
|
||||
void* Mutex_Create(void) {
|
||||
if (mutexIndex == Array_Elems(mutexList)) ErrorHandler_Fail("Cannot allocate mutex");
|
||||
if (mutexIndex == Array_Elems(mutexList)) Logger_Abort("Cannot allocate mutex");
|
||||
CRITICAL_SECTION* ptr = &mutexList[mutexIndex];
|
||||
InitializeCriticalSection(ptr); mutexIndex++;
|
||||
return ptr;
|
||||
@ -696,14 +696,14 @@ void Mutex_Unlock(void* handle) { LeaveCriticalSection((CRITICAL_SECTION*)handle
|
||||
void* Waitable_Create(void) {
|
||||
void* handle = CreateEvent(NULL, false, false, NULL);
|
||||
if (!handle) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Creating waitable");
|
||||
Logger_Abort2(GetLastError(), "Creating waitable");
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Waitable_Free(void* handle) {
|
||||
if (!CloseHandle((HANDLE)handle)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Freeing waitable");
|
||||
Logger_Abort2(GetLastError(), "Freeing waitable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,7 +727,7 @@ void* Thread_StartCallback(void* lpParam) {
|
||||
void* Thread_Start(Thread_StartFunc* func, bool detach) {
|
||||
pthread_t* ptr = Mem_Alloc(1, sizeof(pthread_t), "allocating thread");
|
||||
int res = pthread_create(ptr, NULL, Thread_StartCallback, func);
|
||||
if (res) ErrorHandler_Fail2(res, "Creating thread");
|
||||
if (res) Logger_Abort2(res, "Creating thread");
|
||||
|
||||
if (detach) Thread_Detach(ptr);
|
||||
return ptr;
|
||||
@ -736,61 +736,61 @@ void* Thread_Start(Thread_StartFunc* func, bool detach) {
|
||||
void Thread_Detach(void* handle) {
|
||||
pthread_t* ptr = handle;
|
||||
int res = pthread_detach(*ptr);
|
||||
if (res) ErrorHandler_Fail2(res, "Detaching thread");
|
||||
if (res) Logger_Abort2(res, "Detaching thread");
|
||||
Mem_Free(ptr);
|
||||
}
|
||||
|
||||
void Thread_Join(void* handle) {
|
||||
pthread_t* ptr = handle;
|
||||
int res = pthread_join(*ptr, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "Joining thread");
|
||||
if (res) Logger_Abort2(res, "Joining thread");
|
||||
Mem_Free(ptr);
|
||||
}
|
||||
|
||||
void* Mutex_Create(void) {
|
||||
pthread_mutex_t* ptr = Mem_Alloc(1, sizeof(pthread_mutex_t), "allocating mutex");
|
||||
int res = pthread_mutex_init(ptr, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "Creating mutex");
|
||||
if (res) Logger_Abort2(res, "Creating mutex");
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void Mutex_Free(void* handle) {
|
||||
int res = pthread_mutex_destroy((pthread_mutex_t*)handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Destroying mutex");
|
||||
if (res) Logger_Abort2(res, "Destroying mutex");
|
||||
Mem_Free(handle);
|
||||
}
|
||||
|
||||
void Mutex_Lock(void* handle) {
|
||||
int res = pthread_mutex_lock((pthread_mutex_t*)handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Locking mutex");
|
||||
if (res) Logger_Abort2(res, "Locking mutex");
|
||||
}
|
||||
|
||||
void Mutex_Unlock(void* handle) {
|
||||
int res = pthread_mutex_unlock((pthread_mutex_t*)handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Unlocking mutex");
|
||||
if (res) Logger_Abort2(res, "Unlocking mutex");
|
||||
}
|
||||
|
||||
void* Waitable_Create(void) {
|
||||
pthread_cond_t* ptr = Mem_Alloc(1, sizeof(pthread_cond_t), "allocating waitable");
|
||||
int res = pthread_cond_init(ptr, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "Creating event");
|
||||
if (res) Logger_Abort2(res, "Creating event");
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void Waitable_Free(void* handle) {
|
||||
int res = pthread_cond_destroy((pthread_cond_t*)handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Destroying event");
|
||||
if (res) Logger_Abort2(res, "Destroying event");
|
||||
Mem_Free(handle);
|
||||
}
|
||||
|
||||
void Waitable_Signal(void* handle) {
|
||||
int res = pthread_cond_signal((pthread_cond_t*)handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Signalling event");
|
||||
if (res) Logger_Abort2(res, "Signalling event");
|
||||
}
|
||||
|
||||
void Waitable_Wait(void* handle) {
|
||||
int res = pthread_cond_wait((pthread_cond_t*)handle, &event_mutex);
|
||||
if (res) ErrorHandler_Fail2(res, "Waiting event");
|
||||
if (res) Logger_Abort2(res, "Waiting event");
|
||||
}
|
||||
|
||||
void Waitable_WaitFor(void* handle, uint32_t milliseconds) {
|
||||
@ -806,7 +806,7 @@ void Waitable_WaitFor(void* handle, uint32_t milliseconds) {
|
||||
|
||||
res = pthread_cond_timedwait((pthread_cond_t*)handle, &event_mutex, &ts);
|
||||
if (res == ETIMEDOUT) return;
|
||||
if (res) ErrorHandler_Fail2(res, "Waiting timed event");
|
||||
if (res) Logger_Abort2(res, "Waiting timed event");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -922,7 +922,7 @@ void Font_Make(FontDesc* desc, const String* fontName, int size, int style) {
|
||||
desc->Style = style;
|
||||
|
||||
path = Font_Lookup(fontName, style);
|
||||
if (!path.length) ErrorHandler_Fail("Unknown font");
|
||||
if (!path.length) Logger_Abort("Unknown font");
|
||||
|
||||
stream = Mem_AllocCleared(1, sizeof(FT_StreamRec), "leaky font"); /* TODO: LEAKS MEMORY!!! */
|
||||
if (!Font_MakeArgs(&path, stream, &args)) return;
|
||||
@ -937,11 +937,11 @@ void Font_Make(FontDesc* desc, const String* fontName, int size, int style) {
|
||||
#endif
|
||||
|
||||
err = FT_New_Face(ft_lib, &args, 0, &face);
|
||||
if (err) ErrorHandler_Fail2(err, "Creating font failed");
|
||||
if (err) Logger_Abort2(err, "Creating font failed");
|
||||
desc->Handle = face;
|
||||
|
||||
err = FT_Set_Char_Size(face, size * 64, 0, DPI_DEVICE, 0);
|
||||
if (err) ErrorHandler_Fail2(err, "Resizing font failed");
|
||||
if (err) Logger_Abort2(err, "Resizing font failed");
|
||||
}
|
||||
|
||||
void Font_Free(FontDesc* desc) {
|
||||
@ -955,7 +955,7 @@ void Font_Free(FontDesc* desc) {
|
||||
|
||||
face = desc->Handle;
|
||||
err = FT_Done_Face(face);
|
||||
if (err) ErrorHandler_Fail2(err, "Deleting font failed");
|
||||
if (err) Logger_Abort2(err, "Deleting font failed");
|
||||
desc->Handle = NULL;
|
||||
}
|
||||
|
||||
@ -1173,7 +1173,7 @@ static void Font_Init(void) {
|
||||
ft_mem.realloc = FT_ReallocWrapper;
|
||||
|
||||
err = FT_New_Library(&ft_mem, &ft_lib);
|
||||
if (err) ErrorHandler_Fail2(err, "Failed to init freetype");
|
||||
if (err) Logger_Abort2(err, "Failed to init freetype");
|
||||
|
||||
FT_Add_Default_Modules(ft_lib);
|
||||
FT_Set_Default_Properties(ft_lib);
|
||||
@ -1194,7 +1194,7 @@ static void Font_Init(void) {
|
||||
void Socket_Create(SocketHandle* socketResult) {
|
||||
*socketResult = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (*socketResult == -1) {
|
||||
ErrorHandler_Fail2(Socket__Error(), "Failed to create socket");
|
||||
Logger_Abort2(Socket__Error(), "Failed to create socket");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1334,7 +1334,7 @@ static HINTERNET hInternet;
|
||||
void Http_Init(void) {
|
||||
/* TODO: Should we use INTERNET_OPEN_TYPE_PRECONFIG instead? */
|
||||
hInternet = InternetOpenA(GAME_APP_NAME, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
|
||||
if (!hInternet) ErrorHandler_Fail2(GetLastError(), "Failed to init WinINet");
|
||||
if (!hInternet) Logger_Abort2(GetLastError(), "Failed to init WinINet");
|
||||
}
|
||||
|
||||
static ReturnCode Http_Make(struct AsyncRequest* req, HINTERNET* handle) {
|
||||
@ -1458,10 +1458,10 @@ CURL* curl;
|
||||
|
||||
void Http_Init(void) {
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
if (res) ErrorHandler_Fail2(res, "Failed to init curl");
|
||||
if (res) Logger_Abort2(res, "Failed to init curl");
|
||||
|
||||
curl = curl_easy_init();
|
||||
if (!curl) ErrorHandler_Fail("Failed to init easy curl");
|
||||
if (!curl) Logger_Abort("Failed to init easy curl");
|
||||
}
|
||||
|
||||
static int Http_Progress(int* progress, double total, double received, double a, double b) {
|
||||
@ -1620,7 +1620,7 @@ void Audio_Init(AudioHandle* handle, int buffers) {
|
||||
ctx->Count = buffers;
|
||||
return;
|
||||
}
|
||||
ErrorHandler_Fail("No free audio contexts");
|
||||
Logger_Abort("No free audio contexts");
|
||||
}
|
||||
|
||||
ReturnCode Audio_Free(AudioHandle handle) {
|
||||
@ -1717,18 +1717,18 @@ static volatile int audio_refs;
|
||||
|
||||
static void Audio_CheckContextErrors(void) {
|
||||
ALenum err = alcGetError(audio_device);
|
||||
if (err) ErrorHandler_Fail2(err, "Error creating OpenAL context");
|
||||
if (err) Logger_Abort2(err, "Error creating OpenAL context");
|
||||
}
|
||||
|
||||
static void Audio_CreateContext(void) {
|
||||
audio_device = alcOpenDevice(NULL);
|
||||
if (!audio_device) ErrorHandler_Fail("Failed to create OpenAL device");
|
||||
if (!audio_device) Logger_Abort("Failed to create OpenAL device");
|
||||
Audio_CheckContextErrors();
|
||||
|
||||
audio_context = alcCreateContext(audio_device, NULL);
|
||||
if (!audio_context) {
|
||||
alcCloseDevice(audio_device);
|
||||
ErrorHandler_Fail("Failed to create OpenAL context");
|
||||
Logger_Abort("Failed to create OpenAL context");
|
||||
}
|
||||
Audio_CheckContextErrors();
|
||||
|
||||
@ -1773,7 +1773,7 @@ void Audio_Init(AudioHandle* handle, int buffers) {
|
||||
|
||||
alDistanceModel(AL_NONE);
|
||||
err = alGetError();
|
||||
if (err) { ErrorHandler_Fail2(err, "DistanceModel"); }
|
||||
if (err) { Logger_Abort2(err, "DistanceModel"); }
|
||||
|
||||
for (i = 0; i < Array_Elems(Audio_Contexts); i++) {
|
||||
struct AudioContext* ctx = &Audio_Contexts[i];
|
||||
@ -1788,7 +1788,7 @@ void Audio_Init(AudioHandle* handle, int buffers) {
|
||||
ctx->Source = -1;
|
||||
return;
|
||||
}
|
||||
ErrorHandler_Fail("No free audio contexts");
|
||||
Logger_Abort("No free audio contexts");
|
||||
}
|
||||
|
||||
ReturnCode Audio_Free(AudioHandle handle) {
|
||||
@ -1821,7 +1821,7 @@ static ALenum GetALFormat(int channels, int bitsPerSample) {
|
||||
if (channels == 1) return AL_FORMAT_MONO8;
|
||||
if (channels == 2) return AL_FORMAT_STEREO8;
|
||||
}
|
||||
ErrorHandler_Fail("Unsupported audio format"); return 0;
|
||||
Logger_Abort("Unsupported audio format"); return 0;
|
||||
}
|
||||
|
||||
ReturnCode Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
||||
@ -1935,7 +1935,7 @@ ReturnCode Audio_StopAndFree(AudioHandle handle) {
|
||||
int Platform_ConvertString(void* data, const String* src) {
|
||||
TCHAR* dst = data;
|
||||
int i;
|
||||
if (src->length > FILENAME_SIZE) ErrorHandler_Fail("String too long to expand");
|
||||
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");
|
||||
|
||||
for (i = 0; i < src->length; i++) {
|
||||
*dst = Convert_CP437ToUnicode(src->buffer[i]); dst++;
|
||||
@ -1953,7 +1953,7 @@ void Platform_Init(void) {
|
||||
heap = GetProcessHeap();
|
||||
|
||||
res = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (res) ErrorHandler_Fail2(res, "WSAStartup failed");
|
||||
if (res) Logger_Abort2(res, "WSAStartup failed");
|
||||
}
|
||||
|
||||
void Platform_Free(void) {
|
||||
@ -2123,7 +2123,7 @@ int Platform_ConvertString(void* data, const String* src) {
|
||||
|
||||
Codepoint cp;
|
||||
int i, len = 0;
|
||||
if (src->length > FILENAME_SIZE) ErrorHandler_Fail("String too long to expand");
|
||||
if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand");
|
||||
|
||||
for (i = 0; i < src->length; i++) {
|
||||
cur = dst + len;
|
||||
@ -2227,7 +2227,7 @@ ReturnCode Platform_GetSymbol(void* lib, const char* name, void** symbol) {
|
||||
static void Platform_InitDisplay(void) {
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
int screen;
|
||||
if (!display) ErrorHandler_Fail("Failed to open display");
|
||||
if (!display) Logger_Abort("Failed to open display");
|
||||
|
||||
DisplayDevice_Meta = display;
|
||||
screen = DefaultScreen(display);
|
||||
|
@ -71,14 +71,8 @@ int main(int argc, char** argv) {
|
||||
uint8_t ip[4];
|
||||
uint16_t port;
|
||||
|
||||
argsCount = Platform_GetCommandLineArgs(argc, argv, args);
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565"); */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200"); */
|
||||
/* argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); */
|
||||
|
||||
Platform_SetWorkingDir();
|
||||
ErrorHandler_Init();
|
||||
Logger_Hook();
|
||||
Platform_Init();
|
||||
#ifdef CC_TEST_VORBIS
|
||||
main_imdct();
|
||||
@ -91,6 +85,12 @@ int main(int argc, char** argv) {
|
||||
Utils_EnsureDirectory("plugins");
|
||||
Options_Load();
|
||||
|
||||
argsCount = Platform_GetCommandLineArgs(argc, argv, args);
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565"); */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200"); */
|
||||
/* argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); */
|
||||
|
||||
if (argsCount == 0) {
|
||||
Launcher_Run();
|
||||
} else if (argsCount == 1) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Utils.h"
|
||||
#include "Vorbis.h"
|
||||
#include "Errors.h"
|
||||
#include "Logger.h"
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------List/Checker----------------------------------------------------*
|
||||
@ -81,13 +82,13 @@ static void Resources_CheckTextures(void) {
|
||||
if (!File_Exists(&path)) return;
|
||||
res = Stream_OpenFile(&stream, &path);
|
||||
|
||||
if (res) { Launcher_ShowError(res, "checking default.zip"); return; }
|
||||
if (res) { Logger_Warn(res, "checking default.zip"); return; }
|
||||
Zip_Init(&state, &stream);
|
||||
state.SelectEntry = Resources_SelectZipEntry;
|
||||
|
||||
res = Zip_Extract(&state);
|
||||
stream.Close(&stream);
|
||||
if (res) Launcher_ShowError(res, "inspecting default.zip");
|
||||
if (res) Logger_Warn(res, "inspecting default.zip");
|
||||
|
||||
/* if somehow have say "gui.png", "GUI.png" */
|
||||
Textures_AllExist = texturesFound >= Array_Elems(Resources_Textures);
|
||||
@ -574,13 +575,13 @@ static void TexPatcher_MakeDefaultZip(void) {
|
||||
|
||||
res = Stream_CreateFile(&s, &path);
|
||||
if (res) {
|
||||
Launcher_ShowError(res, "creating default.zip");
|
||||
Logger_Warn(res, "creating default.zip");
|
||||
} else {
|
||||
res = TexPatcher_WriteEntries(&s);
|
||||
if (res) Launcher_ShowError(res, "making default.zip");
|
||||
if (res) Logger_Warn(res, "making default.zip");
|
||||
|
||||
res = s.Close(&s);
|
||||
if (res) Launcher_ShowError(res, "closing default.zip");
|
||||
if (res) Logger_Warn(res, "closing default.zip");
|
||||
}
|
||||
|
||||
for (i = 0; i < Array_Elems(Resources_Files); i++) {
|
||||
@ -601,9 +602,9 @@ static void SoundPatcher_FixupHeader(struct Stream* s, struct VorbisState* ctx)
|
||||
ReturnCode res;
|
||||
|
||||
res = s->Length(s, &length);
|
||||
if (res) { Launcher_ShowError(res, "getting .wav length"); return; }
|
||||
if (res) { Logger_Warn(res, "getting .wav length"); return; }
|
||||
res = s->Seek(s, 0);
|
||||
if (res) { Launcher_ShowError(res, "seeking to .wav start"); return; }
|
||||
if (res) { Logger_Warn(res, "seeking to .wav start"); return; }
|
||||
|
||||
Stream_SetU32_BE(&header[0], WAV_FourCC('R','I','F','F'));
|
||||
Stream_SetU32_LE(&header[4], length - 8);
|
||||
@ -621,7 +622,7 @@ static void SoundPatcher_FixupHeader(struct Stream* s, struct VorbisState* ctx)
|
||||
Stream_SetU32_LE(&header[40], length - sizeof(header));
|
||||
|
||||
res = Stream_Write(s, header, sizeof(header));
|
||||
if (res) Launcher_ShowError(res, "fixing .wav header");
|
||||
if (res) Logger_Warn(res, "fixing .wav header");
|
||||
}
|
||||
|
||||
static void SoundPatcher_DecodeAudio(struct Stream* s, struct VorbisState* ctx) {
|
||||
@ -631,21 +632,21 @@ static void SoundPatcher_DecodeAudio(struct Stream* s, struct VorbisState* ctx)
|
||||
|
||||
/* ctx is all 0, so reuse it here for header */
|
||||
res = Stream_Write(s, ctx, 44);
|
||||
if (res) { Launcher_ShowError(res, "writing .wav header"); return; }
|
||||
if (res) { Logger_Warn(res, "writing .wav header"); return; }
|
||||
|
||||
res = Vorbis_DecodeHeaders(ctx);
|
||||
if (res) { Launcher_ShowError(res, "decoding .ogg header"); return; }
|
||||
if (res) { Logger_Warn(res, "decoding .ogg header"); return; }
|
||||
samples = Mem_Alloc(ctx->BlockSizes[1] * ctx->Channels, 2, ".ogg samples");
|
||||
|
||||
for (;;) {
|
||||
res = Vorbis_DecodeFrame(ctx);
|
||||
if (res == ERR_END_OF_STREAM) break;
|
||||
if (res) { Launcher_ShowError(res, "decoding .ogg"); break; }
|
||||
if (res) { Logger_Warn(res, "decoding .ogg"); break; }
|
||||
|
||||
count = Vorbis_OutputFrame(ctx, samples);
|
||||
/* TODO: Do we need to account for big endian */
|
||||
res = Stream_Write(s, samples, count * 2);
|
||||
if (res) { Launcher_ShowError(res, "writing samples"); break; }
|
||||
if (res) { Logger_Warn(res, "writing samples"); break; }
|
||||
}
|
||||
Mem_Free(samples);
|
||||
}
|
||||
@ -662,7 +663,7 @@ static void SoundPatcher_Save(struct ResourceSound* sound, struct AsyncRequest*
|
||||
String_Format1(&path, "audio/%c.wav", sound->Name);
|
||||
|
||||
res = Stream_CreateFile(&dst, &path);
|
||||
if (res) { Launcher_ShowError(res, "creating .wav file"); return; }
|
||||
if (res) { Logger_Warn(res, "creating .wav file"); return; }
|
||||
|
||||
Ogg_MakeStream(&ogg, buffer, &src);
|
||||
ctx.Source = &ogg;
|
||||
@ -671,7 +672,7 @@ static void SoundPatcher_Save(struct ResourceSound* sound, struct AsyncRequest*
|
||||
SoundPatcher_FixupHeader(&dst, &ctx);
|
||||
|
||||
res = dst.Close(&dst);
|
||||
if (res) Launcher_ShowError(res, "closing .wav file");
|
||||
if (res) Logger_Warn(res, "closing .wav file");
|
||||
}
|
||||
|
||||
static void MusicPatcher_Save(struct ResourceMusic* music, struct AsyncRequest* req) {
|
||||
@ -682,7 +683,7 @@ static void MusicPatcher_Save(struct ResourceMusic* music, struct AsyncRequest*
|
||||
String_Format1(&path, "audio/%c", music->Name);
|
||||
|
||||
res = Stream_WriteAllTo(&path, req->Data, req->Size);
|
||||
if (res) Launcher_ShowError(res, "saving music file");
|
||||
if (res) Logger_Warn(res, "saving music file");
|
||||
}
|
||||
|
||||
|
||||
|
@ -293,7 +293,7 @@ static void MPConnection_FailConnect(ReturnCode result) {
|
||||
|
||||
if (result) {
|
||||
String_Format3(&msg, "Error connecting to %s:%i: %i", &Game_IPAddress, &Game_Port, &result);
|
||||
ErrorHandler_Log(&msg);
|
||||
Logger_Log(&msg);
|
||||
msg.length = 0;
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
|
||||
String_InitArray(msg, msgBuffer);
|
||||
String_Format3(&msg, "Error reading from %s:%i: %i", &Game_IPAddress, &Game_Port, &res);
|
||||
|
||||
ErrorHandler_Log(&msg);
|
||||
Logger_Log(&msg);
|
||||
Game_Disconnect(&title_lost, &reason_err);
|
||||
return;
|
||||
}
|
||||
|
24
src/String.c
24
src/String.c
@ -52,13 +52,13 @@ void String_Copy(String* dst, const String* src) {
|
||||
|
||||
String String_UNSAFE_Substring(STRING_REF const String* str, int offset, int length) {
|
||||
if (offset < 0 || offset > str->length) {
|
||||
ErrorHandler_Fail("Offset for substring out of range");
|
||||
Logger_Abort("Offset for substring out of range");
|
||||
}
|
||||
if (length < 0 || length > str->length) {
|
||||
ErrorHandler_Fail("Length for substring out of range");
|
||||
Logger_Abort("Length for substring out of range");
|
||||
}
|
||||
if (offset + length > str->length) {
|
||||
ErrorHandler_Fail("Result substring is out of range");
|
||||
Logger_Abort("Result substring is out of range");
|
||||
}
|
||||
return String_Init(str->buffer + offset, length, length);
|
||||
}
|
||||
@ -299,10 +299,10 @@ void String_InsertAt(String* str, int offset, char c) {
|
||||
int i;
|
||||
|
||||
if (offset < 0 || offset > str->length) {
|
||||
ErrorHandler_Fail("Offset for InsertAt out of range");
|
||||
Logger_Abort("Offset for InsertAt out of range");
|
||||
}
|
||||
if (str->length == str->capacity) {
|
||||
ErrorHandler_Fail("Cannot insert character into full string");
|
||||
Logger_Abort("Cannot insert character into full string");
|
||||
}
|
||||
|
||||
for (i = str->length; i > offset; i--) {
|
||||
@ -316,7 +316,7 @@ void String_DeleteAt(String* str, int offset) {
|
||||
int i;
|
||||
|
||||
if (offset < 0 || offset >= str->length) {
|
||||
ErrorHandler_Fail("Offset for DeleteAt out of range");
|
||||
Logger_Abort("Offset for DeleteAt out of range");
|
||||
}
|
||||
|
||||
for (i = offset; i < str->length - 1; i++) {
|
||||
@ -466,7 +466,7 @@ void String_Format4(String* str, const char* format, const void* a1, const void*
|
||||
case '%':
|
||||
String_Append(str, '%'); break;
|
||||
default:
|
||||
ErrorHandler_Fail("Invalid type for string format");
|
||||
Logger_Abort("Invalid type for string format");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -767,7 +767,7 @@ void StringsBuffer_Get(StringsBuffer* buffer, int i, String* str) {
|
||||
|
||||
String StringsBuffer_UNSAFE_Get(StringsBuffer* buffer, int i) {
|
||||
uint32_t flags, offset, len;
|
||||
if (i < 0 || i >= buffer->Count) ErrorHandler_Fail("Tried to get String past StringsBuffer end");
|
||||
if (i < 0 || i >= buffer->Count) Logger_Abort("Tried to get String past StringsBuffer end");
|
||||
|
||||
flags = buffer->FlagsBuffer[i];
|
||||
offset = flags >> STRINGSBUFFER_LEN_SHIFT;
|
||||
@ -786,7 +786,7 @@ void StringsBuffer_Add(StringsBuffer* buffer, const String* str) {
|
||||
}
|
||||
|
||||
if (str->length > STRINGSBUFFER_LEN_MASK) {
|
||||
ErrorHandler_Fail("String too big to insert into StringsBuffer");
|
||||
Logger_Abort("String too big to insert into StringsBuffer");
|
||||
}
|
||||
|
||||
textOffset = buffer->TotalLength;
|
||||
@ -805,7 +805,7 @@ void StringsBuffer_Add(StringsBuffer* buffer, const String* str) {
|
||||
void StringsBuffer_Remove(StringsBuffer* buffer, int index) {
|
||||
uint32_t flags, offset, len;
|
||||
uint32_t i, offsetAdj;
|
||||
if (index < 0 || index >= buffer->Count) ErrorHandler_Fail("Tried to remove String past StringsBuffer end");
|
||||
if (index < 0 || index >= buffer->Count) Logger_Abort("Tried to remove String past StringsBuffer end");
|
||||
|
||||
flags = buffer->FlagsBuffer[index];
|
||||
offset = flags >> STRINGSBUFFER_LEN_SHIFT;
|
||||
@ -895,7 +895,7 @@ void WordWrap_GetCoords(int index, const String* lines, int numLines, int* coord
|
||||
int WordWrap_GetBackLength(const String* text, int index) {
|
||||
int start = index;
|
||||
if (index <= 0) return 0;
|
||||
if (index >= text->length) ErrorHandler_Fail("WordWrap_GetBackLength - index past end of string");
|
||||
if (index >= text->length) Logger_Abort("WordWrap_GetBackLength - index past end of string");
|
||||
|
||||
/* Go backward to the end of the previous word */
|
||||
while (index > 0 && text->buffer[index] == ' ') index--;
|
||||
@ -908,7 +908,7 @@ int WordWrap_GetBackLength(const String* text, int index) {
|
||||
int WordWrap_GetForwardLength(const String* text, int index) {
|
||||
int start = index, length = text->length;
|
||||
if (index == -1) return 0;
|
||||
if (index >= text->length) ErrorHandler_Fail("WordWrap_GetForwardLength - index past end of string");
|
||||
if (index >= text->length) Logger_Abort("WordWrap_GetForwardLength - index past end of string");
|
||||
|
||||
/* Go forward to the end of the word 'index' is currently in */
|
||||
while (index < length && text->buffer[index] != ' ') index++;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "ExtMath.h"
|
||||
#include "Chat.h"
|
||||
#include "Options.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#define LIQUID_ANIM_MAX 64
|
||||
/* Based off the incredible work from https://dl.dropboxusercontent.com/u/12694594/lava.txt
|
||||
@ -180,7 +181,7 @@ static void Animations_ReadDescription(struct Stream* stream, const String* path
|
||||
for (;;) {
|
||||
res = Stream_ReadLine(&buffered, &line);
|
||||
if (res == ERR_END_OF_STREAM) break;
|
||||
if (res) { Chat_LogError2(res, "reading from", path); break; }
|
||||
if (res) { Logger_Warn2(res, "reading from", path); break; }
|
||||
|
||||
if (!line.length || line.buffer[0] == '#') continue;
|
||||
count = String_UNSAFE_Split(&line, ' ', parts, ANIM_MIN_ARGS);
|
||||
@ -354,7 +355,7 @@ static void Animations_FileChanged(void* obj, struct Stream* stream, const Strin
|
||||
res = Png_Decode(&anims_bmp, stream);
|
||||
if (!res) return;
|
||||
|
||||
Chat_LogError2(res, "decoding", name);
|
||||
Logger_Warn2(res, "decoding", name);
|
||||
Mem_Free(anims_bmp.Scan0);
|
||||
anims_bmp.Scan0 = NULL;
|
||||
} else if (String_CaselessEqualsConst(name, "animations.txt")) {
|
||||
@ -545,7 +546,7 @@ bool TextureCache_Get(const String* url, struct Stream* stream) {
|
||||
res = Stream_OpenFile(stream, &path);
|
||||
|
||||
if (res == ReturnCode_FileNotFound) return false;
|
||||
if (res) { Chat_LogError2(res, "opening cache for", url); return false; }
|
||||
if (res) { Logger_Warn2(res, "opening cache for", url); return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -573,7 +574,7 @@ void TextureCache_GetLastModified(const String* url, TimeMS* time) {
|
||||
TextureCache_MakePath(&path, url);
|
||||
|
||||
res = File_GetModifiedTime(&path, time);
|
||||
if (res) { Chat_LogError2(res, "getting last modified time of", url); *time = 0; }
|
||||
if (res) { Logger_Warn2(res, "getting last modified time of", url); *time = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -590,7 +591,7 @@ void TextureCache_Set(const String* url, uint8_t* data, uint32_t length) {
|
||||
if (!Utils_EnsureDirectory("texturecache")) return;
|
||||
|
||||
res = Stream_WriteAllTo(&path, data, length);
|
||||
if (res) { Chat_LogError2(res, "caching", url); }
|
||||
if (res) { Logger_Warn2(res, "caching", url); }
|
||||
}
|
||||
|
||||
CC_NOINLINE static void TextureCache_SetEntry(const String* url, const String* data, struct EntryList* list) {
|
||||
@ -647,13 +648,13 @@ void TexturePack_ExtractZip_File(const String* filename) {
|
||||
String_Format1(&path, "texpacks/%s", filename);
|
||||
|
||||
res = Stream_OpenFile(&stream, &path);
|
||||
if (res) { Chat_LogError2(res, "opening", &path); return; }
|
||||
if (res) { Logger_Warn2(res, "opening", &path); return; }
|
||||
|
||||
res = TexturePack_ExtractZip(&stream);
|
||||
if (res) { Chat_LogError2(res, "extracting", &path); }
|
||||
if (res) { Logger_Warn2(res, "extracting", &path); }
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", &path); }
|
||||
if (res) { Logger_Warn2(res, "closing", &path); }
|
||||
}
|
||||
|
||||
ReturnCode TexturePack_ExtractTerrainPng(struct Stream* stream) {
|
||||
@ -697,11 +698,11 @@ void TexturePack_ExtractCurrent(const String* url) {
|
||||
|
||||
res = zip ? TexturePack_ExtractZip(&stream) :
|
||||
TexturePack_ExtractTerrainPng(&stream);
|
||||
if (res) Chat_LogError2(res, zip ? "extracting" : "decoding", url);
|
||||
if (res) Logger_Warn2(res, zip ? "extracting" : "decoding", url);
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing cache for", url); }
|
||||
if (res) Logger_Warn2(res, "closing cache for", url);
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,6 +728,6 @@ void TexturePack_Extract_Req(struct AsyncRequest* item) {
|
||||
res = png ? TexturePack_ExtractTerrainPng(&mem)
|
||||
: TexturePack_ExtractZip(&mem);
|
||||
|
||||
if (res) Chat_LogError2(res, png ? "decoding" : "extracting", &url);
|
||||
if (res) Logger_Warn2(res, png ? "decoding" : "extracting", &url);
|
||||
ASyncRequest_Free(item);
|
||||
}
|
||||
|
15
src/Utils.c
15
src/Utils.c
@ -5,6 +5,7 @@
|
||||
#include "Platform.h"
|
||||
#include "Stream.h"
|
||||
#include "Errors.h"
|
||||
#include "ErrorHandler.h"
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
@ -131,7 +132,7 @@ bool Utils_EnsureDirectory(const char* dirName) {
|
||||
if (Directory_Exists(&dir)) return true;
|
||||
|
||||
res = Directory_Create(&dir);
|
||||
if (res) { Chat_LogError2(res, "creating directory", &dir); }
|
||||
if (res) { Logger_Warn2(res, "creating directory", &dir); }
|
||||
return res == 0;
|
||||
}
|
||||
|
||||
@ -310,7 +311,7 @@ void EntryList_Load(struct EntryList* list, EntryList_Filter filter) {
|
||||
|
||||
res = Stream_OpenFile(&stream, &path);
|
||||
if (res == ReturnCode_FileNotFound) return;
|
||||
if (res) { Chat_LogError2(res, "opening", &path); return; }
|
||||
if (res) { Logger_Warn2(res, "opening", &path); return; }
|
||||
|
||||
/* ReadLine reads single byte at a time */
|
||||
Stream_ReadonlyBuffered(&buffered, &stream, buffer, sizeof(buffer));
|
||||
@ -319,7 +320,7 @@ void EntryList_Load(struct EntryList* list, EntryList_Filter filter) {
|
||||
for (;;) {
|
||||
res = Stream_ReadLine(&buffered, &entry);
|
||||
if (res == ERR_END_OF_STREAM) break;
|
||||
if (res) { Chat_LogError2(res, "reading from", &path); break; }
|
||||
if (res) { Logger_Warn2(res, "reading from", &path); break; }
|
||||
|
||||
String_UNSAFE_TrimStart(&entry);
|
||||
String_UNSAFE_TrimEnd(&entry);
|
||||
@ -332,7 +333,7 @@ void EntryList_Load(struct EntryList* list, EntryList_Filter filter) {
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", &path); }
|
||||
if (res) { Logger_Warn2(res, "closing", &path); }
|
||||
}
|
||||
|
||||
void EntryList_Save(struct EntryList* list) {
|
||||
@ -350,16 +351,16 @@ void EntryList_Save(struct EntryList* list) {
|
||||
}
|
||||
|
||||
res = Stream_CreateFile(&stream, &path);
|
||||
if (res) { Chat_LogError2(res, "creating", &path); return; }
|
||||
if (res) { Logger_Warn2(res, "creating", &path); return; }
|
||||
|
||||
for (i = 0; i < list->Entries.Count; i++) {
|
||||
entry = StringsBuffer_UNSAFE_Get(&list->Entries, i);
|
||||
res = Stream_WriteLine(&stream, &entry);
|
||||
if (res) { Chat_LogError2(res, "writing to", &path); break; }
|
||||
if (res) { Logger_Warn2(res, "writing to", &path); break; }
|
||||
}
|
||||
|
||||
res = stream.Close(&stream);
|
||||
if (res) { Chat_LogError2(res, "closing", &path); }
|
||||
if (res) { Logger_Warn2(res, "closing", &path); }
|
||||
}
|
||||
|
||||
int EntryList_Remove(struct EntryList* list, const String* key) {
|
||||
|
10
src/Vorbis.c
10
src/Vorbis.c
@ -1,5 +1,5 @@
|
||||
#include "Vorbis.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Platform.h"
|
||||
#include "Event.h"
|
||||
#include "Block.h"
|
||||
@ -110,7 +110,7 @@ static uint32_t Vorbis_ReadBits(struct VorbisState* ctx, uint32_t bitsCount) {
|
||||
|
||||
while (ctx->NumBits < bitsCount) {
|
||||
res = ctx->Source->ReadU8(ctx->Source, &portion);
|
||||
if (res) { ErrorHandler_Fail2(res, "Failed to read byte for vorbis"); }
|
||||
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
||||
Vorbis_PushByte(ctx, portion);
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ static uint32_t Vorbis_ReadBit(struct VorbisState* ctx) {
|
||||
|
||||
if (!ctx->NumBits) {
|
||||
res = ctx->Source->ReadU8(ctx->Source, &portion);
|
||||
if (res) { ErrorHandler_Fail2(res, "Failed to read byte for vorbis"); }
|
||||
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
||||
Vorbis_PushByte(ctx, portion);
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ static uint32_t Codebook_DecodeScalar(struct VorbisState* ctx, struct Codebook*
|
||||
codewords += c->NumCodewords[depth];
|
||||
values += c->NumCodewords[depth];
|
||||
}
|
||||
ErrorHandler_Fail("Invalid huffman code");
|
||||
Logger_Abort("Invalid huffman code");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ static void Codebook_DecodeVectors(struct VorbisState* ctx, struct Codebook* c,
|
||||
if (c->SequenceP) last = value;
|
||||
}
|
||||
} else {
|
||||
ErrorHandler_Fail("Invalid huffman code");
|
||||
Logger_Abort("Invalid huffman code");
|
||||
}
|
||||
}
|
||||
|
||||
|
84
src/Window.c
84
src/Window.c
@ -2,7 +2,7 @@
|
||||
#include "Platform.h"
|
||||
#include "Input.h"
|
||||
#include "Event.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "Funcs.h"
|
||||
|
||||
bool Window_Exists, Window_Focused;
|
||||
@ -392,15 +392,15 @@ void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mod
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
|
||||
ATOM atom = RegisterClassEx(&wc);
|
||||
if (!atom) ErrorHandler_Fail2(GetLastError(), "Failed to register window class");
|
||||
if (!atom) Logger_Abort2(GetLastError(), "Failed to register window class");
|
||||
|
||||
win_handle = CreateWindowEx(0, atom, NULL, CC_WIN_STYLE,
|
||||
rect.left, rect.top, Rect_Width(rect), Rect_Height(rect),
|
||||
NULL, NULL, win_instance, NULL);
|
||||
if (!win_handle) ErrorHandler_Fail2(GetLastError(), "Failed to create window");
|
||||
if (!win_handle) Logger_Abort2(GetLastError(), "Failed to create window");
|
||||
|
||||
win_DC = GetDC(win_handle);
|
||||
if (!win_DC) ErrorHandler_Fail2(GetLastError(), "Failed to get device context");
|
||||
if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context");
|
||||
Window_Exists = true;
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ void Window_SetWindowState(int state) {
|
||||
Point2D Window_PointToClient(int x, int y) {
|
||||
Point2D point = { x, y };
|
||||
if (!ScreenToClient(win_handle, &point)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Converting point from client to screen coordinates");
|
||||
Logger_Abort2(GetLastError(), "Converting point from client to screen coordinates");
|
||||
}
|
||||
return point;
|
||||
}
|
||||
@ -577,7 +577,7 @@ Point2D Window_PointToClient(int x, int y) {
|
||||
Point2D Window_PointToScreen(int x, int y) {
|
||||
Point2D point = { x, y };
|
||||
if (!ClientToScreen(win_handle, &point)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Converting point from screen to client coordinates");
|
||||
Logger_Abort2(GetLastError(), "Converting point from screen to client coordinates");
|
||||
}
|
||||
return point;
|
||||
}
|
||||
@ -659,7 +659,7 @@ void GLContext_SelectGraphicsMode(struct GraphicsMode* mode) {
|
||||
if (mode->Buffers > 1) pfd.dwFlags |= PFD_DOUBLEBUFFER;
|
||||
|
||||
int modeIndex = ChoosePixelFormat(win_DC, &pfd);
|
||||
if (modeIndex == 0) { ErrorHandler_Fail("Requested graphics mode not available"); }
|
||||
if (modeIndex == 0) { Logger_Abort("Requested graphics mode not available"); }
|
||||
|
||||
Mem_Set(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
@ -667,7 +667,7 @@ void GLContext_SelectGraphicsMode(struct GraphicsMode* mode) {
|
||||
|
||||
DescribePixelFormat(win_DC, modeIndex, pfd.nSize, &pfd);
|
||||
if (!SetPixelFormat(win_DC, modeIndex, &pfd)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "SetPixelFormat failed");
|
||||
Logger_Abort2(GetLastError(), "SetPixelFormat failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,11 +684,11 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
||||
ctx_Handle = wglCreateContext(win_DC);
|
||||
}
|
||||
if (!ctx_Handle) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Failed to create OpenGL context");
|
||||
Logger_Abort2(GetLastError(), "Failed to create OpenGL context");
|
||||
}
|
||||
|
||||
if (!wglMakeCurrent(win_DC, ctx_Handle)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Failed to make OpenGL context current");
|
||||
Logger_Abort2(GetLastError(), "Failed to make OpenGL context current");
|
||||
}
|
||||
|
||||
ctx_DC = wglGetCurrentDC();
|
||||
@ -699,7 +699,7 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
||||
void GLContext_Update(void) { }
|
||||
void GLContext_Free(void) {
|
||||
if (!wglDeleteContext(ctx_Handle)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Failed to destroy OpenGL context");
|
||||
Logger_Abort2(GetLastError(), "Failed to destroy OpenGL context");
|
||||
}
|
||||
ctx_Handle = NULL;
|
||||
}
|
||||
@ -711,7 +711,7 @@ void* GLContext_GetAddress(const char* function) {
|
||||
|
||||
void GLContext_SwapBuffers(void) {
|
||||
if (!SwapBuffers(ctx_DC)) {
|
||||
ErrorHandler_Fail2(GetLastError(), "Failed to swap buffers");
|
||||
Logger_Abort2(GetLastError(), "Failed to swap buffers");
|
||||
}
|
||||
}
|
||||
|
||||
@ -944,7 +944,7 @@ void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mod
|
||||
win_handle = XCreateWindow(win_display, win_rootWin, x, y, width, height,
|
||||
0, win_visual.depth /* CopyFromParent*/, InputOutput, win_visual.visual,
|
||||
CWColormap | CWEventMask | CWBackPixel | CWBorderPixel, &attributes);
|
||||
if (!win_handle) ErrorHandler_Fail("XCreateWindow failed");
|
||||
if (!win_handle) Logger_Abort("XCreateWindow failed");
|
||||
|
||||
hints.base_width = width;
|
||||
hints.base_height = height;
|
||||
@ -1673,13 +1673,13 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
||||
Platform_LogConst("Context create failed. Trying indirect...");
|
||||
ctx_Handle = glXCreateContext(win_display, &win_visual, NULL, false);
|
||||
}
|
||||
if (!ctx_Handle) ErrorHandler_Fail("Failed to create OpenGL context");
|
||||
if (!ctx_Handle) Logger_Abort("Failed to create OpenGL context");
|
||||
|
||||
if (!glXIsDirect(win_display, ctx_Handle)) {
|
||||
Platform_LogConst("== WARNING: Context is not direct ==");
|
||||
}
|
||||
if (!glXMakeCurrent(win_display, win_handle, ctx_Handle)) {
|
||||
ErrorHandler_Fail("Failed to make OpenGL context current.");
|
||||
Logger_Abort("Failed to make OpenGL context current.");
|
||||
}
|
||||
|
||||
/* GLX may return non-null function pointers that don't actually work */
|
||||
@ -1762,7 +1762,7 @@ static XVisualInfo GLContext_SelectVisual(struct GraphicsMode* mode) {
|
||||
|
||||
GLContext_GetAttribs(mode, attribs);
|
||||
if (!glXQueryVersion(win_display, &major, &minor)) {
|
||||
ErrorHandler_Fail("glXQueryVersion failed");
|
||||
Logger_Abort("glXQueryVersion failed");
|
||||
}
|
||||
|
||||
if (major >= 1 && minor >= 3) {
|
||||
@ -1780,7 +1780,7 @@ static XVisualInfo GLContext_SelectVisual(struct GraphicsMode* mode) {
|
||||
visual = glXChooseVisual(win_display, win_screen, attribs);
|
||||
}
|
||||
if (!visual) {
|
||||
ErrorHandler_Fail("Requested GraphicsMode not available.");
|
||||
Logger_Abort("Requested GraphicsMode not available.");
|
||||
}
|
||||
|
||||
info = *visual;
|
||||
@ -1843,14 +1843,14 @@ static void Window_UpdateSize(void) {
|
||||
if (win_state == WINDOW_STATE_FULLSCREEN) return;
|
||||
|
||||
res = GetWindowBounds(win_handle, kWindowStructureRgn, &r);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting window bounds");
|
||||
if (res) Logger_Abort2(res, "Getting window bounds");
|
||||
Window_Bounds.X = r.left;
|
||||
Window_Bounds.Y = r.top;
|
||||
Window_Bounds.Width = Rect_Width(r);
|
||||
Window_Bounds.Height = Rect_Height(r);
|
||||
|
||||
res = GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting window clientsize");
|
||||
if (res) Logger_Abort2(res, "Getting window clientsize");
|
||||
Window_ClientSize.Width = Rect_Width(r);
|
||||
Window_ClientSize.Height = Rect_Height(r);
|
||||
}
|
||||
@ -1869,20 +1869,20 @@ static void Window_UpdateWindowState(void) {
|
||||
meaning they are maximised up to their reported ideal size. So report a large ideal size. */
|
||||
idealSize.v = 9000; idealSize.h = 9000;
|
||||
res = ZoomWindowIdeal(win_handle, inZoomOut, &idealSize);
|
||||
if (res) ErrorHandler_Fail2(res, "Maximising window");
|
||||
if (res) Logger_Abort2(res, "Maximising window");
|
||||
break;
|
||||
|
||||
case WINDOW_STATE_NORMAL:
|
||||
if (Window_GetWindowState() == WINDOW_STATE_MAXIMISED) {
|
||||
idealSize.v = 0; idealSize.h = 0;
|
||||
res = ZoomWindowIdeal(win_handle, inZoomIn, &idealSize);
|
||||
if (res) ErrorHandler_Fail2(res, "Un-maximising window");
|
||||
if (res) Logger_Abort2(res, "Un-maximising window");
|
||||
}
|
||||
break;
|
||||
|
||||
case WINDOW_STATE_MINIMISED:
|
||||
res = CollapseWindow(win_handle, true);
|
||||
if (res) ErrorHandler_Fail2(res, "Minimising window");
|
||||
if (res) Logger_Abort2(res, "Minimising window");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1905,11 +1905,11 @@ OSStatus Window_ProcessKeyboardEvent(EventHandlerCallRef inCaller, EventRef inEv
|
||||
case kEventRawKeyUp:
|
||||
res = GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32,
|
||||
NULL, sizeof(UInt32), NULL, &code);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting key button");
|
||||
if (res) Logger_Abort2(res, "Getting key button");
|
||||
|
||||
res = GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar,
|
||||
NULL, sizeof(char), NULL, &charCode);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting key char");
|
||||
if (res) Logger_Abort2(res, "Getting key char");
|
||||
|
||||
key = Window_MapKey(code);
|
||||
if (key == KEY_NONE) {
|
||||
@ -1939,7 +1939,7 @@ OSStatus Window_ProcessKeyboardEvent(EventHandlerCallRef inCaller, EventRef inEv
|
||||
case kEventRawKeyModifiersChanged:
|
||||
res = GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32,
|
||||
NULL, sizeof(UInt32), NULL, &code);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting key modifiers");
|
||||
if (res) Logger_Abort2(res, "Getting key modifiers");
|
||||
|
||||
/* TODO: Is this even needed */
|
||||
repeat = Key_KeyRepeat;
|
||||
@ -2012,7 +2012,7 @@ OSStatus Window_ProcessMouseEvent(EventHandlerCallRef inCaller, EventRef inEvent
|
||||
|
||||
/* this error comes up from the application event handler */
|
||||
if (res && res != eventParameterNotFoundErr) {
|
||||
ErrorHandler_Fail2(res, "Getting mouse position");
|
||||
Logger_Abort2(res, "Getting mouse position");
|
||||
}
|
||||
|
||||
mousePos.X = (int)pt.x; mousePos.Y = (int)pt.y;
|
||||
@ -2028,7 +2028,7 @@ OSStatus Window_ProcessMouseEvent(EventHandlerCallRef inCaller, EventRef inEvent
|
||||
down = kind == kEventMouseDown;
|
||||
res = GetEventParameter(inEvent, kEventParamMouseButton, typeMouseButton,
|
||||
NULL, sizeof(EventMouseButton), NULL, &button);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting mouse button");
|
||||
if (res) Logger_Abort2(res, "Getting mouse button");
|
||||
|
||||
switch (button) {
|
||||
case kEventMouseButtonPrimary:
|
||||
@ -2043,7 +2043,7 @@ OSStatus Window_ProcessMouseEvent(EventHandlerCallRef inCaller, EventRef inEvent
|
||||
case kEventMouseWheelMoved:
|
||||
res = GetEventParameter(inEvent, kEventParamMouseWheelDelta, typeSInt32,
|
||||
NULL, sizeof(SInt32), NULL, &delta);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting mouse wheel delta");
|
||||
if (res) Logger_Abort2(res, "Getting mouse wheel delta");
|
||||
Mouse_SetWheel(Mouse_Wheel + delta);
|
||||
return 0;
|
||||
|
||||
@ -2119,7 +2119,7 @@ static void Window_ConnectEvents(void) {
|
||||
/* but if use WindowEventTargetRef, can't click quit/move buttons anymore */
|
||||
res = InstallEventHandler(target, NewEventHandlerUPP(Window_EventHandler),
|
||||
Array_Elems(eventTypes), eventTypes, NULL, NULL);
|
||||
if (res) ErrorHandler_Fail2(res, "Connecting events");
|
||||
if (res) Logger_Abort2(res, "Connecting events");
|
||||
}
|
||||
|
||||
|
||||
@ -2137,14 +2137,14 @@ void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mod
|
||||
kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute |
|
||||
kWindowInWindowMenuAttribute | kWindowLiveResizeAttribute,
|
||||
&r, &win_handle);
|
||||
if (res) ErrorHandler_Fail2(res, "Failed to create window");
|
||||
if (res) Logger_Abort2(res, "Failed to create window");
|
||||
|
||||
Window_SetLocation(r.left, r.right);
|
||||
Window_SetSize(Rect_Width(r), Rect_Height(r));
|
||||
Window_UpdateSize();
|
||||
|
||||
res = GetWindowBounds(win_handle, kWindowTitleBarRgn, &r);
|
||||
if (res) ErrorHandler_Fail2(res, "Failed to get titlebar size");
|
||||
if (res) Logger_Abort2(res, "Failed to get titlebar size");
|
||||
title_height = Rect_Height(r);
|
||||
AcquireRootMenu();
|
||||
|
||||
@ -2175,7 +2175,7 @@ PasteboardRef Window_GetPasteboard(void) {
|
||||
PasteboardRef pbRef;
|
||||
OSStatus err = PasteboardCreate(kPasteboardClipboard, &pbRef);
|
||||
|
||||
if (err) ErrorHandler_Fail2(err, "Creating Pasteboard reference");
|
||||
if (err) Logger_Abort2(err, "Creating Pasteboard reference");
|
||||
PasteboardSynchronize(pbRef);
|
||||
return pbRef;
|
||||
}
|
||||
@ -2194,11 +2194,11 @@ void Window_GetClipboardText(String* value) {
|
||||
pbRef = Window_GetPasteboard();
|
||||
|
||||
err = PasteboardGetItemCount(pbRef, &itemCount);
|
||||
if (err) ErrorHandler_Fail2(err, "Getting item count from Pasteboard");
|
||||
if (err) Logger_Abort2(err, "Getting item count from Pasteboard");
|
||||
if (itemCount < 1) return;
|
||||
|
||||
err = PasteboardGetItemIdentifier(pbRef, 1, &itemID);
|
||||
if (err) ErrorHandler_Fail2(err, "Getting item identifier from Pasteboard");
|
||||
if (err) Logger_Abort2(err, "Getting item identifier from Pasteboard");
|
||||
|
||||
if (!(err = PasteboardCopyItemFlavorData(pbRef, itemID, FMT_UTF16, &outData))) {
|
||||
ptr = CFDataGetBytePtr(outData);
|
||||
@ -2220,12 +2220,12 @@ void Window_SetClipboardText(const String* value) {
|
||||
|
||||
pbRef = Window_GetPasteboard();
|
||||
err = PasteboardClear(pbRef);
|
||||
if (err) ErrorHandler_Fail2(err, "Clearing Pasteboard");
|
||||
if (err) Logger_Abort2(err, "Clearing Pasteboard");
|
||||
PasteboardSynchronize(pbRef);
|
||||
|
||||
len = Platform_ConvertString(str, value);
|
||||
cfData = CFDataCreate(NULL, str, len);
|
||||
if (!cfData) ErrorHandler_Fail("CFDataCreate() returned null pointer");
|
||||
if (!cfData) Logger_Abort("CFDataCreate() returned null pointer");
|
||||
|
||||
PasteboardPutItemFlavor(pbRef, 1, FMT_UTF8, cfData, 0);
|
||||
}
|
||||
@ -2269,7 +2269,7 @@ void Window_SetWindowState(int state) {
|
||||
}
|
||||
if (old_state == WINDOW_STATE_MINIMISED) {
|
||||
err = CollapseWindow(win_handle, false);
|
||||
if (err) ErrorHandler_Fail2(err, "Un-minimising window");
|
||||
if (err) Logger_Abort2(err, "Un-minimising window");
|
||||
}
|
||||
Window_UpdateWindowState();
|
||||
}
|
||||
@ -2408,7 +2408,7 @@ void Window_DrawRaw(Rect2D r) {
|
||||
OSStatus err;
|
||||
|
||||
err = QDBeginCGContext(win_winPort, &context);
|
||||
if (err) ErrorHandler_Fail2(err, "Begin draw");
|
||||
if (err) Logger_Abort2(err, "Begin draw");
|
||||
|
||||
/* TODO: Only update changed bit.. */
|
||||
rect.origin.x = 0; rect.origin.y = 0;
|
||||
@ -2418,7 +2418,7 @@ void Window_DrawRaw(Rect2D r) {
|
||||
CGContextDrawImage(context, rect, win_image);
|
||||
CGContextSynchronize(context);
|
||||
err = QDEndCGContext(win_winPort, &context);
|
||||
if (err) ErrorHandler_Fail2(err, "End draw");
|
||||
if (err) Logger_Abort2(err, "End draw");
|
||||
}
|
||||
|
||||
|
||||
@ -2434,7 +2434,7 @@ static void GLContext_Check(int code, const char* place) {
|
||||
if (code) return;
|
||||
|
||||
res = aglGetError();
|
||||
if (res) ErrorHandler_Fail2(res, place);
|
||||
if (res) Logger_Abort2(res, place);
|
||||
}
|
||||
|
||||
static void GLContext_MakeCurrent(void) {
|
||||
@ -2527,7 +2527,7 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
||||
|
||||
/* Initially try creating fullscreen compatible context */
|
||||
res = DMGetGDeviceByDisplayID(CGMainDisplayID(), &gdevice, false);
|
||||
if (res) ErrorHandler_Fail2(res, "Getting display device failed");
|
||||
if (res) Logger_Abort2(res, "Getting display device failed");
|
||||
|
||||
GLContext_GetAttribs(mode, attribs, true);
|
||||
fmt = aglChoosePixelFormat(&gdevice, 1, attribs);
|
||||
@ -2542,7 +2542,7 @@ void GLContext_Init(struct GraphicsMode* mode) {
|
||||
fmt = aglChoosePixelFormat(NULL, 0, attribs);
|
||||
res = aglGetError();
|
||||
}
|
||||
if (res) ErrorHandler_Fail2(res, "Choosing pixel format");
|
||||
if (res) Logger_Abort2(res, "Choosing pixel format");
|
||||
|
||||
ctx_handle = aglCreateContext(fmt, NULL);
|
||||
GLContext_Check(0, "Creating GL context");
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "World.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Logger.h"
|
||||
#include "String.h"
|
||||
#include "Platform.h"
|
||||
#include "Event.h"
|
||||
@ -66,7 +66,7 @@ void World_SetNewMap(BlockRaw* blocks, int blocksSize, int width, int height, in
|
||||
if (!World_BlocksSize) World_Blocks = NULL;
|
||||
|
||||
if (blocksSize != (width * height * length)) {
|
||||
ErrorHandler_Fail("Blocks array size does not match volume of map");
|
||||
Logger_Abort("Blocks array size does not match volume of map");
|
||||
}
|
||||
#ifdef EXTENDED_BLOCKS
|
||||
World_Blocks2 = World_Blocks;
|
||||
|
Loading…
x
Reference in New Issue
Block a user