Skip to content

'SILK_DISABLE_ERRORS' macro idea #2

@EimaKve

Description

@EimaKve

Currently the Silk API always checks for if the specified buffer is NULL and if is, write an error message. While this is a nice feature, it would be even better if the end-user were to be given an option to disable any error logging operations for performance reasons, similar to how assert works in C when you enable the NDEBUG macro. This would also make it easier to write checks as this would make copy-pasting the same if scope redundant.

An example of how this could be done and used:

#if !defined(SILK_DISABLE_ERRORS)
    #define SILK_ASSERT_NOT_NULL(ptr) \
        if (ptr == nil) { \
            silkAssignErrorMessage(SILK_ERR_BUF_INVALID); \
            return SILK_FAILURE; \
        } do {} while (0)
#else 
    #define SILK_ASSERT_NOT_NULL(ptr) do {} while(0)
#endif

...

SILK_API i32 silkDrawRect(pixel* buffer, vec2i buf_size, i32 buf_stride, vec2i position, vec2i size, pixel pix) {
    /* NOTE(EimaMei): It's pretty useless to check if the buffer is null here considering we don't access anything from it, plus the following function, silkDrawRectPro, does the same check but I digress. */
    SILK_ASSERT_NOT_NULL(buffer);
    
    silkDrawRectPro(
        buffer, 
        buf_size,
        buf_stride,
        position, 
        size, 
        (i32) 0, 
        (vec2i) { 0 },
        pix
    );

    return SILK_SUCCESS;
}

SILK_API i32 silkDrawRectPro(pixel* buffer, vec2i buf_size, i32 buf_stride, vec2i position, vec2i size, i32 angle, vec2i offset, pixel pix) {
    SILK_ASSERT_NOT_NULL(buffer);
    ....

    return SILK_SUCCESS;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions