LIBRETRO: Add checks for LibretroPalette colors ptr

This commit is contained in:
Giovanni Cascione 2023-11-10 16:42:23 +01:00
parent 1aa02751ea
commit 3fffa3de00
3 changed files with 20 additions and 2 deletions

View File

@ -49,12 +49,14 @@ public:
class LibretroPalette {
public:
const byte *_prevColorsSource;
unsigned char _colors[256 * 3];
LibretroPalette(void);
~LibretroPalette(void) {};
void set(const byte *colors, uint start, uint num);
void get(byte *colors, uint start, uint num) const;
unsigned char *getColor(uint aIndex) const;
void reset(void) { _prevColorsSource = NULL; }
};
class OSystem_libretro : public EventsBaseBackend, public PaletteManager {

View File

@ -123,6 +123,8 @@ void OSystem_libretro::engineInit() {
ConfMan.setBool("original_gui", false);
retro_log_cb(RETRO_LOG_INFO, "\"original_gui\" setting forced to false\n");
}
_mousePalette.reset();
_gamePalette.reset();
}
void OSystem_libretro::engineDone() {

View File

@ -198,12 +198,26 @@ static INLINE void copyRectToSurface(uint8 *pixels, int out_pitch, const uint8 *
} while (--h);
}
LibretroPalette::LibretroPalette() {
LibretroPalette::LibretroPalette() : _prevColorsSource(NULL){
memset(_colors, 0, sizeof(_colors));
}
void LibretroPalette::set(const byte *colors, uint start, uint num) {
memcpy(_colors + start * 3, colors, num * 3);
/* TODO: This check is a workaround to handle a SEGFAULT in iOS due to the call from SmushPlayer::play in scumm engine,
caused by the corruption of start argument (and consequently colors ptr). Root cause to be investigated. */
if (start > 255) {
start = 0;
colors=_prevColorsSource;
}else
_prevColorsSource = colors;
if (num>256)
num=256;
if (colors)
memcpy(_colors + start * 3, colors, num * 3);
else
LIBRETRO_G_SYSTEM->logMessage(LogMessageType::kError,"LibretroPalette colors ptr is NULL\n");
}
void LibretroPalette::get(byte *colors, uint start, uint num) const {