Update error and debug logging methods
Some checks failed
Build Dusk / run-tests (push) Failing after 14s
Build Dusk / build-linux (push) Failing after 15s
Build Dusk / build-psp (push) Failing after 22s
Build Dusk / build-gamecube (push) Failing after 18s
Build Dusk / build-wii (push) Failing after 15s

This commit is contained in:
2026-03-11 10:33:43 -05:00
parent 1d7516982a
commit d21cd7f78b
30 changed files with 147 additions and 144 deletions

View File

@@ -187,7 +187,6 @@ function sceneUpdate()
end
if inputIsDown(INPUT_ACTION_DOWN) then
print("down")
y = y + 1
end

View File

@@ -46,7 +46,7 @@ dusk_env_to_h(duskdefs.env duskdefs.h)
# Subdirs
add_subdirectory(assert)
add_subdirectory(asset)
add_subdirectory(debug)
add_subdirectory(log)
add_subdirectory(display)
add_subdirectory(engine)
add_subdirectory(error)

View File

@@ -6,7 +6,7 @@
*/
#include "assert.h"
#include "debug/debug.h"
#include "log/log.h"
#ifndef DUSK_ASSERTIONS_FAKED
#ifdef DUSK_TEST_ASSERT
@@ -31,14 +31,12 @@
const char *message
) {
if(x != true) {
debugPrint(
logError(
"Assertion Failed in %s:%i\n\n%s\n",
file,
line,
message
);
debugFlush();
abort();
}
}

View File

@@ -11,7 +11,6 @@
#include "assert/assert.h"
#include "asset/assettype.h"
#include "engine/engine.h"
#include "debug/debug.h"
#include "util/string.h"
asset_t ASSET;

View File

@@ -12,7 +12,6 @@
#include "display/mesh/quad.h"
#include "display/screen/screen.h"
#include "ui/ui.h"
#include "debug/debug.h"
#include "display/text/text.h"
#include "assert/assert.h"
#include "util/memory.h"

View File

@@ -8,7 +8,6 @@
#include "mesh.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "debug/debug.h"
errorret_t meshInit(
mesh_t *mesh,

View File

@@ -7,7 +7,6 @@
#include "quad.h"
#include "assert/assert.h"
#include "debug/debug.h"
mesh_t QUAD_MESH_SIMPLE;
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {

View File

@@ -9,7 +9,7 @@
#include "error.h"
#include "util/memory.h"
#include "util/string.h"
#include "debug/debug.h"
#include "log/log.h"
errorstate_t ERROR_STATE = { 0 };
@@ -125,12 +125,11 @@ errorret_t errorPrint(const errorret_t retval) {
assertNotNull(retval.state, "Error state cannot be NULL");
assertNotNull(retval.state->message, "Message cannot be NULL");
debugPrint(
logError(
ERROR_PRINT_FORMAT,
retval.state->code,
retval.state->message,
retval.state->lines
);
debugFlush();
return retval;
}

View File

@@ -11,7 +11,6 @@
#include "util/string.h"
#include "util/math.h"
#include "time/time.h"
#include "debug/debug.h"
input_t INPUT;

View File

@@ -14,9 +14,13 @@
* @param message The message format string.
* @param ... Additional arguments for the format string.
*/
void debugPrint(const char_t *message, ...);
void logDebug(const char_t *message, ...);
/**
* Flushes the debug output buffer.
* Prints a message to the error console. For some platforms this will pause
* the program.
*
* @param message The message format string.
* @param ... Additional arguments for the format string.
*/
void debugFlush();
void logError(const char_t *message, ...);

View File

@@ -6,7 +6,7 @@
#include "scene.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "debug/debug.h"
#include "log/log.h"
#include "time/time.h"
#include "display/camera/camera.h"
#include "display/screen/screen.h"
@@ -84,8 +84,7 @@ void sceneDispose(void) {
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
lua_pop(SCENE.scriptContext.luaState, 1);
debugPrint("Failed to call function '%s': %s\n", "sceneDispose", strErr);
debugFlush();
logDebug("Failed to call function '%s': %s\n", "sceneDispose", strErr);
}
} else {
lua_pop(SCENE.scriptContext.luaState, 1);

View File

@@ -10,7 +10,6 @@
#include "display/texture/tileset.h"
#include "util/memory.h"
#include "util/string.h"
#include "debug/debug.h"
void moduleTileset(scriptcontext_t *ctx) {
assertNotNull(ctx, "Script context cannot be NULL");

View File

@@ -6,7 +6,7 @@
*/
#include "modulesystem.h"
#include "debug/debug.h"
#include "log/log.h"
#include "assert/assert.h"
#include "util/string.h"
#include "script/scriptmodule.h"
@@ -36,8 +36,7 @@ int moduleSysPrint(lua_State *L) {
luaL_pushresult(&b);
const char *msg = lua_tostring(L, -1);
debugPrint("%s\n", msg);
debugFlush();
logDebug("%s\n", msg);
return 0; // no values returned to Lua
}

View File

@@ -9,7 +9,6 @@
#include "assert/assert.h"
#include "asset/asset.h"
#include "util/memory.h"
#include "debug/debug.h"
#include "script/scriptmodule.h"
#include "event/event.h"

View File

@@ -8,7 +8,6 @@
#include "scriptmanager.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "debug/debug.h"
#include "asset/asset.h"
scriptmanager_t SCRIPT_MANAGER;

View File

@@ -10,7 +10,6 @@
#include "assert/assert.h"
#include "display/spritebatch/spritebatch.h"
#include "display/screen/screen.h"
#include "debug/debug.h"
ui_t UI;

View File

@@ -16,6 +16,6 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
# Subdirs
add_subdirectory(asset)
add_subdirectory(debug)
add_subdirectory(log)
add_subdirectory(display)
add_subdirectory(input)

View File

@@ -1,81 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "debug/debug.h"
#include "display/display.h"
#include <debug.h>
static char_t DEBUG_ERROR_BUFFER[16*1024] = {0};
void debugPrint(const char_t *message, ...) {
size_t start = strlen(DEBUG_ERROR_BUFFER);
va_list args;
va_start(args, message);
// Print to stdout
va_list copy;
va_copy(copy, args);
vfprintf(stdout, message, copy);
va_end(copy);
fflush(stdout);
// Append to buffer
// vsnprintf(
// DEBUG_ERROR_BUFFER + start,
// sizeof(DEBUG_ERROR_BUFFER) - start,
// message,
// args
// );
}
void debugFlush() {
fflush(stdout);
// Either create graphics, or hijack the displays' graphics.
// void *xfb = NULL;
// GXRModeObj *rmode = NULL;
// void *framebuffer;
// if(DISPLAY.frameBuffer[0]) {
// console_init(
// DISPLAY.frameBuffer[0],
// 20,
// 20,
// DISPLAY.screenMode->fbWidth,
// DISPLAY.screenMode->xfbHeight,
// DISPLAY.screenMode->fbWidth * VI_DISPLAY_PIX_SZ
// );
// } else {
// VIDEO_Init();
// rmode = VIDEO_GetPreferredMode(NULL);
// framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// console_init(
// framebuffer,
// 20,
// 20,
// rmode->fbWidth,
// rmode->xfbHeight,
// rmode->fbWidth*VI_DISPLAY_PIX_SZ
// );
// VIDEO_Configure(rmode);
// VIDEO_SetNextFramebuffer(framebuffer);
// VIDEO_SetBlack(FALSE);
// VIDEO_Flush();
// VIDEO_WaitVSync();
// if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
// }
// // Printf
// printf("SOB\n");
// printf(DEBUG_ERROR_BUFFER);
// printf("\nEOB.");
while(SYS_MainLoop()) {
VIDEO_WaitVSync();
}
}

View File

@@ -8,7 +8,6 @@
#include "display/mesh/mesh.h"
#include "display/texture/texture.h"
#include "assert/assert.h"
#include "debug/debug.h"
errorret_t meshInitDolphin(
meshdolphin_t *mesh,

View File

@@ -7,7 +7,6 @@
#include "input/input.h"
#include "assert/assert.h"
#include "debug/debug.h"
inputbuttondata_t INPUT_BUTTON_DATA[] = {
#ifdef DUSK_INPUT_GAMEPAD

View File

@@ -7,5 +7,5 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
debug.c
log.c
)

65
src/duskdolphin/log/log.c Normal file
View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "log/log.h"
#include "display/display.h"
#include <debug.h>
void logDebug(const char_t *message, ...) {
// Print to stdout
va_list args;
va_start(args, message);
vfprintf(stdout, message, args);
va_end(args);
fflush(stdout);
}
void logError(const char_t *message, ...) {
// Either create graphics, or hijack the displays' graphics.
void *xfb = NULL;
GXRModeObj *rmode = NULL;
void *framebuffer;
if(DISPLAY.frameBuffer[0]) {
console_init(
DISPLAY.frameBuffer[0],
20,
20,
DISPLAY.screenMode->fbWidth,
DISPLAY.screenMode->xfbHeight,
DISPLAY.screenMode->fbWidth * VI_DISPLAY_PIX_SZ
);
} else {
VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL);
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(
framebuffer,
20,
20,
rmode->fbWidth,
rmode->xfbHeight,
rmode->fbWidth*VI_DISPLAY_PIX_SZ
);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(framebuffer);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}
// Printf
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
while(SYS_MainLoop()) {
VIDEO_WaitVSync();
}
}

View File

@@ -11,5 +11,5 @@ target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
# Subdirs
add_subdirectory(asset)
add_subdirectory(debug)
add_subdirectory(log)
add_subdirectory(input)

View File

@@ -6,5 +6,5 @@
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
debug.c
log.c
)

View File

@@ -5,15 +5,18 @@
* https://opensource.org/licenses/MIT
*/
#include "debug/debug.h"
#include "log/log.h"
void debugPrint(const char_t *message, ...) {
void logDebug(const char_t *message, ...) {
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
}
void debugFlush() {
fflush(stdout);
void logError(const char_t *message, ...) {
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
}

View File

@@ -15,6 +15,6 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
)
# Subdirs
add_subdirectory(debug)
add_subdirectory(asset)
add_subdirectory(input)
add_subdirectory(input)
add_subdirectory(log)

View File

@@ -1,23 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "debug/debug.h"
void debugPrint(const char_t *message, ...) {
FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a");
if(!file) return;
va_list args;
va_start(args, message);
vfprintf(file, message, args);
va_end(args);
fclose(file);
}
void debugFlush() {
fflush(stdout);
}

View File

@@ -7,5 +7,5 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
debug.c
log.c
)

52
src/duskpsp/log/log.c Normal file
View File

@@ -0,0 +1,52 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "log/log.h"
void logDebug(const char_t *message, ...) {
va_list args;
va_start(args, message);
// print to stdout
va_list copy;
va_copy(copy, args);
vprintf(message, copy);
va_end(copy);
// print to file
FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a");
if (file) {
va_copy(copy, args);
vfprintf(file, message, copy);
va_end(copy);
fclose(file);
}
va_end(args);
}
void logError(const char_t *message, ...) {
va_list args;
va_start(args, message);
// print to stderr
va_list copy;
va_copy(copy, args);
vfprintf(stderr, message, copy);
va_end(copy);
// print to file
FILE *file = fopen("ms0:/PSP/GAME/Dusk/error.log", "a");
if (file) {
va_copy(copy, args);
vfprintf(file, message, copy);
va_end(copy);
fclose(file);
}
va_end(args);
}