diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index b67a2b79..fc958c67 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -235,6 +235,11 @@ void Bitmap::Create(int width, int height, int depth, const Bytes &data) { void Bitmap::Create(int width, int height, int depth, int format, const Bytes &data) { + if (data.empty()) { + SDL_Log("Bitmap data is empty\n"); + active_ = false; + return; + } active_ = true; width_ = width; height_ = height; @@ -246,6 +251,11 @@ void Bitmap::Create(int width, int height, int depth, int format, SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_, GetSnesPixelFormat(format)), SDL_Surface_Deleter()); + if (surface_ == nullptr) { + SDL_Log("SDL_CreateRGBSurfaceWithFormat failed: %s\n", SDL_GetError()); + active_ = false; + return; + } surface_->pixels = pixel_data_; active_ = true; } @@ -355,7 +365,7 @@ absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) { sdl_palette->colors[i].a = pal_color.rgb().w; } SDL_LockSurface(surface_.get()); - SDL_RETURN_IF_ERROR() + // SDL_RETURN_IF_ERROR() return absl::OkStatus(); } @@ -379,7 +389,7 @@ absl::Status Bitmap::ApplyPaletteFromPaletteGroup(const SnesPalette &palette, } } SDL_LockSurface(surface_.get()); - SDL_RETURN_IF_ERROR() + // SDL_RETURN_IF_ERROR() return absl::OkStatus(); } @@ -404,7 +414,7 @@ absl::Status Bitmap::ApplyPaletteWithTransparent(const SnesPalette &palette, i++; } SDL_LockSurface(surface_.get()); - SDL_RETURN_IF_ERROR() + // SDL_RETURN_IF_ERROR() return absl::OkStatus(); } diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 1a3ab29d..fe8db58f 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -206,7 +206,7 @@ class Bitmap { bool modified_ = false; void *texture_pixels = nullptr; - uchar *pixel_data_; + uint8_t *pixel_data_ = nullptr; Bytes data_; std::vector png_data_; diff --git a/src/app/gfx/snes_palette.h b/src/app/gfx/snes_palette.h index e5d57a01..421d0a83 100644 --- a/src/app/gfx/snes_palette.h +++ b/src/app/gfx/snes_palette.h @@ -151,14 +151,14 @@ class SnesPalette { void operator()(int i, const SnesColor& color) { if (i >= colors.size()) { - std::cout << SNESPalette: Index out of bounds << std::endl; + std::cout << "SNESPalette: Index out of bounds" << std::endl; } colors[i] = color; } void operator()(int i, const ImVec4& color) { if (i >= colors.size()) { - std::cout << SNESPalette: Index out of bounds << std::endl; + std::cout << "SNESPalette: Index out of bounds" << std::endl; return; } colors[i].set_rgb(color);