xfangfang / borealis

Hardware accelerated, Nintendo Switch inspired UI library for PC, Android, iOS, PSV, PS4 and Nintendo Switch
Apache License 2.0
31 stars 21 forks source link

Make brls::Image::setImageFromMem const correct #47

Closed PoloNX closed 10 months ago

PoloNX commented 10 months ago

NanoVG is an old C library. Unfortunately, in C libraries, the use of const is often absent. This is either because some libraries predate the introduction of the const keyword or, most of the time, due to oversights. NanoVG is no exception and, for example, does not use const for a buffer in the nvgCreateImageMem function

NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);

However, this buffer is used by the

STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *channels_in_file, int desired_channels); 

function, which indeed expects a "const.".

The purpose of this pull request is to make Borealis const-correct. Instead of using const_cast<unsigned char*>(buf) in the source code of a project using Borealis, it is preferable to use only buf and apply const_cast<unsigned char*>(buf) directly within the Borealis library.

xfangfang commented 10 months ago

Looks good to me, Thanks for the fix~