[nostalgia/core] Make invalid palette lookups return 0 instead of garbage memory
This commit is contained in:
parent
c8dc14dd8e
commit
29fd9b8c4f
@ -39,6 +39,13 @@ struct Palette {
|
|||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Palette";
|
||||||
static constexpr auto TypeVersion = 1;
|
static constexpr auto TypeVersion = 1;
|
||||||
ox::Vector<Color16> colors = {};
|
ox::Vector<Color16> colors = {};
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr Color16 color(auto idx) const noexcept {
|
||||||
|
if (idx < colors.size()) [[likely]] {
|
||||||
|
return colors[idx];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Predecessor to TileSheet, kept for backward compatibility
|
// Predecessor to TileSheet, kept for backward compatibility
|
||||||
|
@ -93,7 +93,7 @@ void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize) noexcept {
|
|||||||
m_bufferSet.elements.resize(pixels * VertexEboLength);
|
m_bufferSet.elements.resize(pixels * VertexEboLength);
|
||||||
// set pixels
|
// set pixels
|
||||||
subSheet->walkPixels(m_model->img().bpp, [&](std::size_t i, uint8_t p) {
|
subSheet->walkPixels(m_model->img().bpp, [&](std::size_t i, uint8_t p) {
|
||||||
auto color = pal->colors[p];
|
auto color = pal->color(p);
|
||||||
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
|
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
|
||||||
const auto fx = static_cast<float>(pt.x);
|
const auto fx = static_cast<float>(pt.x);
|
||||||
const auto fy = static_cast<float>(pt.y);
|
const auto fy = static_cast<float>(pt.y);
|
||||||
|
Loading…
Reference in New Issue
Block a user