[nostalgia/core/studio] Fix crash that occurs when a non-leaf node subsheet is selected

This commit is contained in:
Gary Talent 2025-01-11 16:05:47 -06:00
parent 4f55964dd9
commit 6b0ce40c02
2 changed files with 11 additions and 1 deletions

View File

@ -80,6 +80,11 @@ void TileSheetGrid::setBufferObject(
} }
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept { void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
if (subsheet.columns < 1 || subsheet.rows < 1) {
m_bufferSet.elements.clear();
m_bufferSet.vertices.clear();
return;
}
auto const pixSize = pixelSize(paneSize); auto const pixSize = pixelSize(paneSize);
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) { auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength]; auto const vbo = &m_bufferSet.vertices[i * VertexVboLength];

View File

@ -51,7 +51,7 @@ ox::Error TileSheetPixels::buildShader() noexcept {
return glutils::buildShaderProgram(s_programSrc).moveTo(m_shader); return glutils::buildShaderProgram(s_programSrc).moveTo(m_shader);
} }
void TileSheetPixels::draw(bool update, ox::Vec2 const&scroll) noexcept { void TileSheetPixels::draw(bool const update, ox::Vec2 const&scroll) noexcept {
glUseProgram(m_shader); glUseProgram(m_shader);
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
if (update) { if (update) {
@ -117,6 +117,11 @@ void TileSheetPixels::setPixelBufferObject(
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept { void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
// set buffer lengths // set buffer lengths
auto const&subSheet = m_model.activeSubSheet(); auto const&subSheet = m_model.activeSubSheet();
if (subSheet.columns < 1 || subSheet.rows < 1) {
m_bufferSet.vertices.clear();
m_bufferSet.elements.clear();
return;
}
auto const&pal = m_model.pal(); auto const&pal = m_model.pal();
auto const width = subSheet.columns * TileWidth; auto const width = subSheet.columns * TileWidth;
auto const height = subSheet.rows * TileHeight; auto const height = subSheet.rows * TileHeight;