Add crash preventions to DynOS_Tex_Get

This commit is contained in:
Agent X 2024-03-22 18:54:24 -04:00
parent 57af112f37
commit a2fd2983b2
8 changed files with 20 additions and 1341 deletions

View file

@ -734,10 +734,10 @@ void Print(const char *aFmt, Args... aArgs) {
} }
template <typename... Args> template <typename... Args>
void PrintConsole(const char *aFmt, Args... aArgs) { void PrintConsole(enum ConsoleMessageLevel level, const char *aFmt, Args... aArgs) {
snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, aFmt, aArgs...); snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, aFmt, aArgs...);
sys_swap_backslashes(gDjuiConsoleTmpBuffer); sys_swap_backslashes(gDjuiConsoleTmpBuffer);
djui_console_message_create(gDjuiConsoleTmpBuffer, CONSOLE_MESSAGE_INFO); djui_console_message_create(gDjuiConsoleTmpBuffer, level);
} }
template <typename... Args> template <typename... Args>
@ -750,7 +750,7 @@ void PrintError(const char *aFmt, Args... aArgs) {
#define PrintDataError(...) { \ #define PrintDataError(...) { \
if (aGfxData->mErrorCount == 0) Print(" ERROR!"); \ if (aGfxData->mErrorCount == 0) Print(" ERROR!"); \
Print(__VA_ARGS__); \ Print(__VA_ARGS__); \
PrintConsole(__VA_ARGS__); \ PrintConsole(CONSOLE_MESSAGE_ERROR, __VA_ARGS__); \
aGfxData->mErrorCount++; \ aGfxData->mErrorCount++; \
} }

View file

@ -188,7 +188,7 @@ static void DynOS_Actor_Generate(const SysPath &aPackFolder, Array<Pair<u64, Str
// Parse data // Parse data
PrintNoNewLine("%s.bin: Model identifier: %X - Processing... ", _GeoRootName.begin(), _GfxData->mModelIdentifier); PrintNoNewLine("%s.bin: Model identifier: %X - Processing... ", _GeoRootName.begin(), _GfxData->mModelIdentifier);
PrintConsole("%s.bin: Model identifier: %X - Processing... ", _GeoRootName.begin(), _GfxData->mModelIdentifier); PrintConsole(CONSOLE_MESSAGE_INFO, "%s.bin: Model identifier: %X - Processing... ", _GeoRootName.begin(), _GfxData->mModelIdentifier);
DynOS_Geo_Parse(_GfxData, _GeoNode, true); DynOS_Geo_Parse(_GfxData, _GeoNode, true);
// Init animation data // Init animation data

View file

@ -2626,7 +2626,7 @@ static void DynOS_Bhv_Generate(const SysPath &aPackFolder, Array<Pair<u64, Strin
// Parse data // Parse data
PrintNoNewLine("%s.bhv: Model identifier: %X - Processing... ", _BhvRootName.begin(), _GfxData->mModelIdentifier); PrintNoNewLine("%s.bhv: Model identifier: %X - Processing... ", _BhvRootName.begin(), _GfxData->mModelIdentifier);
PrintConsole("%s.bhv: Model identifier: %X - Processing... ", _BhvRootName.begin(), _GfxData->mModelIdentifier); PrintConsole(CONSOLE_MESSAGE_INFO, "%s.bhv: Model identifier: %X - Processing... ", _BhvRootName.begin(), _GfxData->mModelIdentifier);
DynOS_Bhv_Parse(_GfxData, _BhvNode, true); DynOS_Bhv_Parse(_GfxData, _BhvNode, true);
// Write if no error // Write if no error

View file

@ -706,7 +706,7 @@ void DynOS_Col_Generate(const SysPath &aPackFolder, Array<Pair<u64, String>> _Ac
// Parse data // Parse data
PrintNoNewLine("%s.col: Model identifier: %X - Processing... ", _ColRootName.begin(), _GfxData->mModelIdentifier); PrintNoNewLine("%s.col: Model identifier: %X - Processing... ", _ColRootName.begin(), _GfxData->mModelIdentifier);
PrintConsole("%s.col: Model identifier: %X - Processing... ", _ColRootName.begin(), _GfxData->mModelIdentifier); PrintConsole(CONSOLE_MESSAGE_INFO, "%s.col: Model identifier: %X - Processing... ", _ColRootName.begin(), _GfxData->mModelIdentifier);
DynOS_Col_Parse(_GfxData, _ColNode, true); DynOS_Col_Parse(_GfxData, _ColNode, true);
// Write if no error // Write if no error

View file

@ -1097,7 +1097,7 @@ static bool DynOS_Lvl_GeneratePack_Internal(const SysPath &aPackFolder, Array<Pa
// Parse data // Parse data
PrintNoNewLine("%s.lvl: Model identifier: %X - Processing... ", _LvlRootName.begin(), _GfxData->mModelIdentifier); PrintNoNewLine("%s.lvl: Model identifier: %X - Processing... ", _LvlRootName.begin(), _GfxData->mModelIdentifier);
PrintConsole("%s.lvl: Model identifier: %X - Processing... ", _LvlRootName.begin(), _GfxData->mModelIdentifier); PrintConsole(CONSOLE_MESSAGE_INFO, "%s.lvl: Model identifier: %X - Processing... ", _LvlRootName.begin(), _GfxData->mModelIdentifier);
DynOS_Lvl_Parse(_GfxData, _LvlRoot, true); DynOS_Lvl_Parse(_GfxData, _LvlRoot, true);
// Force all of the movtexs, collisions, and trajectories into the compiled lvl // Force all of the movtexs, collisions, and trajectories into the compiled lvl

View file

@ -462,6 +462,19 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
// load the texture if it hasn't been yet // load the texture if it hasn't been yet
if (_Data->mRawData.begin() == NULL) { if (_Data->mRawData.begin() == NULL) {
u8 *_RawData = stbi_load_from_memory(_Data->mPngData.begin(), _Data->mPngData.Count(), &_Data->mRawWidth, &_Data->mRawHeight, NULL, 4); u8 *_RawData = stbi_load_from_memory(_Data->mPngData.begin(), _Data->mPngData.Count(), &_Data->mRawWidth, &_Data->mRawHeight, NULL, 4);
// texture data is corrupted
if (_RawData == NULL) {
PrintError("Attempted to load corrupted tex file: %s", aTexName);
PrintConsole(CONSOLE_MESSAGE_ERROR, "Attempted to load corrupted tex file: %s", aTexName);
return false;
}
// texture width or height is NPOT
if (!(_Data->mRawWidth > 0 && _Data->mRawWidth & (_Data->mRawWidth - 1) == 0) ||
!(_Data->mRawHeight > 0 && _Data->mRawHeight & (_Data->mRawHeight - 1) == 0)) {
PrintError("Attempted to load tex file with non power of two width or height: %s", aTexName);
PrintConsole(CONSOLE_MESSAGE_ERROR, "Attempted to load tex file with non power of two width or height: %s", aTexName);
return false;
}
_Data->mRawFormat = G_IM_FMT_RGBA; _Data->mRawFormat = G_IM_FMT_RGBA;
_Data->mRawSize = G_IM_SIZ_32b; _Data->mRawSize = G_IM_SIZ_32b;
_Data->mRawData = Array<u8>(_RawData, _RawData + (_Data->mRawWidth * _Data->mRawHeight * 4)); _Data->mRawData = Array<u8>(_RawData, _RawData + (_Data->mRawWidth * _Data->mRawHeight * 4));

File diff suppressed because it is too large Load diff

View file

@ -1,110 +0,0 @@
/*
libconfigini - an ini formatted configuration parser library
Copyright (C) 2013-present Taner YILMAZ <taner44@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of copyright holders nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CONFIGINI_H_
#define CONFIGINI_H_
#include <stdio.h>
#include <stdbool.h>
typedef struct Config Config;
#define CONFIG_SECTION_FLAT NULL /* config is flat data (has no section) */
/**
* \brief Return types
*/
typedef enum
{
CONFIG_OK, /* ok (no error) */
CONFIG_ERR_FILE, /* file io error (file not exists, cannot open file, ...) */
CONFIG_ERR_NO_SECTION, /* section does not exist */
CONFIG_ERR_NO_KEY, /* key does not exist */
CONFIG_ERR_MEMALLOC, /* memory allocation failed */
CONFIG_ERR_INVALID_PARAM, /* invalid parametrs (as NULL) */
CONFIG_ERR_INVALID_VALUE, /* value of key is invalid (inconsistent data, empty data) */
CONFIG_ERR_PARSING, /* parsing error of data (does not fit to config format) */
} ConfigRet;
#ifdef __cplusplus
extern "C" {
#endif
Config* ConfigNew (void);
void ConfigFree (Config *cfg);
const char *ConfigRetToString (ConfigRet ret);
ConfigRet ConfigRead (FILE *fp, Config **cfg);
ConfigRet ConfigReadFile (const char *filename, Config **cfg);
ConfigRet ConfigPrint (const Config *cfg, FILE *stream);
ConfigRet ConfigPrintToFile (const Config *cfg, char *filename);
ConfigRet ConfigPrintSettings (const Config *cfg, FILE *stream);
int ConfigGetSectionCount (const Config *cfg);
int ConfigGetKeyCount (const Config *cfg, const char *sect);
ConfigRet ConfigSetCommentCharset(Config *cfg, const char *comment_ch);
ConfigRet ConfigSetKeyValSepChar (Config *cfg, char ch);
ConfigRet ConfigSetBoolString (Config *cfg, const char *true_str, const char *false_str);
ConfigRet ConfigReadString (const Config *cfg, const char *sect, const char *key, char * val, int size, const char * dfl_val);
ConfigRet ConfigReadInt (const Config *cfg, const char *sect, const char *key, int * val, int dfl_val);
ConfigRet ConfigReadUnsignedInt (const Config *cfg, const char *sect, const char *key, unsigned int *val, unsigned int dfl_val);
ConfigRet ConfigReadFloat (const Config *cfg, const char *sect, const char *key, float * val, float dfl_val);
ConfigRet ConfigReadDouble (const Config *cfg, const char *sect, const char *key, double * val, double dfl_val);
ConfigRet ConfigReadBool (const Config *cfg, const char *sect, const char *key, bool * val, bool dfl_val);
ConfigRet ConfigAddString (Config *cfg, const char *sect, const char *key, const char *val);
ConfigRet ConfigAddInt (Config *cfg, const char *sect, const char *key, int val);
ConfigRet ConfigAddUnsignedInt (Config *cfg, const char *sect, const char *key, unsigned int val);
ConfigRet ConfigAddFloat (Config *cfg, const char *sect, const char *key, float val);
ConfigRet ConfigAddDouble (Config *cfg, const char *sect, const char *key, double val);
ConfigRet ConfigAddBool (Config *cfg, const char *sect, const char *key, bool val);
bool ConfigHasSection (const Config *cfg, const char *sect);
ConfigRet ConfigRemoveSection (Config *cfg, const char *sect);
ConfigRet ConfigRemoveKey (Config *cfg, const char *sect, const char *key);
#ifdef __cplusplus
}
#endif
#endif /* CONFIGINI_H_ */