Added memory errors for when files aren't found

This commit is contained in:
Peter Slattery 2020-02-05 00:03:56 -08:00
parent 759b5f6906
commit 58ef0b460f
6 changed files with 43 additions and 7 deletions

View File

@ -53,11 +53,19 @@ struct window_info
typedef struct window window;
#define PLATFORM_MEMORY_NO_ERROR 0
enum platform_memory_error
{
PlatformMemory_NoError,
PlatformMemory_FileNotFound,
PlatformMemory_UnknownError, // You should implement handling this when you see it
};
struct platform_memory_result
{
u8* Base;
s32 Size;
s32 Error;
platform_memory_error Error;
};
struct texture_buffer

View File

@ -93,7 +93,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
r32 FontSize = 14;
{
platform_memory_result FontFile = Context.PlatformReadEntireFile("Anonymous Pro.ttf");
if (FontFile.Size)
if (!FontFile.Error)
{
bitmap_font* Font = PushStruct(&State->Permanent, bitmap_font);
@ -140,7 +140,11 @@ INITIALIZE_APPLICATION(InitializeApplication)
Font->BitmapTextureHandle = Context.PlatformGetGPUTextureHandle(Font->BitmapMemory,
Font->BitmapWidth, Font->BitmapHeight);
} else {}
}
else
{
// TODO(Peter): How do we want to handle not having a font?
}
}
State->Interface.FontSize = FontSize;

View File

@ -77,7 +77,10 @@ internal void
LoadAssembly (app_state* State, context Context, char* Path)
{
platform_memory_result TestAssemblyFile = Context.PlatformReadEntireFile(Path);
Assert(TestAssemblyFile.Size > 0);
if (TestAssemblyFile.Error != PlatformMemory_NoError)
{
return;
}
assembly_definition AssemblyDefinition = ParseAssemblyFile(TestAssemblyFile.Base, TestAssemblyFile.Size, &State->Transient);

View File

@ -47,6 +47,16 @@ typedef CLEANUP_APPLICATION(cleanup_application);
// Platform Functions
// File IO
// TODO(Peter):
struct directory_listing
{
string Path;
directory_listing* Next;
};
// Font
typedef struct platform_font_info platform_font_info;
enum font_weight

View File

@ -11,7 +11,7 @@
PLATFORM_READ_ENTIRE_FILE(Win32ReadEntireFile)
{
platform_memory_result Result = {};
Result.Error = PLATFORM_MEMORY_NO_ERROR;
Result.Error = PlatformMemory_NoError;
HANDLE FileHandle = CreateFileA (Path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@ -30,15 +30,17 @@ PLATFORM_READ_ENTIRE_FILE(Win32ReadEntireFile)
}
else
{
u32 Error = GetLastError();
// TODO(Peter):
Result.Size = 0;
Result.Error = 1;
Result.Error = PlatformMemory_UnknownError;
}
}
CloseHandle(FileHandle);
}
else
{
// TODO(Peter): failure
Result.Error = PlatformMemory_FileNotFound;
}
return Result;
@ -131,6 +133,13 @@ PLATFORM_GET_FILE_PATH(Win32SystemDialogueOpenFile)
return Result;
}
internal directory_listing
EnumerateDirectory(char* Path, memory_arena* Storage)
{
directory_listing Result = {};
// TODO(Peter):
return Result;
}
#define WIN32_FOLDHAUS_FILEIO_H
#endif // WIN32_FOLDHAUS_FILEIO_H

View File

@ -18,6 +18,8 @@ x Hot Code Reloading
- Win32 Platform Layer
x Capture Mouse Events that start on the window but end outside
x Mouse up when mouse down was in the window
- Enumerate Directory Contents (you started this in win32_foldhaus_fileio.h)
-
- File Loading
- Gracefully handle File Not found