Permalink
Browse files

SoftGPU: Fix crash when stride is 0.

This happens in Star Ocean 1.
  • Loading branch information...
unknownbrackets committed Nov 12, 2017
1 parent 9f77d48 commit ffbdb15975373fcdc91f0d7cbb876f10d8a8df7a
Showing with 16 additions and 6 deletions.
  1. +12 −3 GPU/Software/SoftGpu.cpp
  2. +4 −3 ext/native/thin3d/thin3d_vulkan.cpp
View
@@ -155,22 +155,31 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
fbTex = nullptr;
}
// For accuracy, try to handle 0 stride - sometimes used.
if (displayStride_ == 0) {
srcheight = 1;
}
Draw::TextureDesc desc{};
desc.type = Draw::TextureType::LINEAR2D;
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
desc.depth = 1;
desc.mipLevels = 1;
bool hasImage = true;
if (!Memory::IsValidAddress(displayFramebuf_)) {
if (!Memory::IsValidAddress(displayFramebuf_) || srcwidth == 0 || srcheight == 0) {
hasImage = false;
u1 = 1.0f;
} else if (displayFormat_ == GE_FORMAT_8888) {
u8 *data = Memory::GetPointer(displayFramebuf_);
desc.width = displayStride_;
desc.width = displayStride_ == 0 ? srcwidth : displayStride_;
desc.height = srcheight;
desc.initData.push_back(data);
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
u1 = (float)srcwidth / displayStride_;
if (displayStride_ != 0) {
u1 = (float)srcwidth / displayStride_;
} else {
u1 = 1.0f;
}
} else {
// TODO: This should probably be converted in a shader instead..
fbTexBuffer.resize(srcwidth * srcheight);
@@ -312,8 +312,9 @@ struct DescriptorSetKey {
class VKTexture : public Texture {
public:
VKTexture(VulkanContext *vulkan, VkCommandBuffer cmd, const TextureDesc &desc)
: vulkan_(vulkan), format_(desc.format), mipLevels_(desc.mipLevels) {
Create(cmd, desc);
: vulkan_(vulkan), mipLevels_(desc.mipLevels), format_(desc.format) {
bool result = Create(cmd, desc);
assert(result);
}
~VKTexture() {
@@ -336,7 +337,7 @@ class VKTexture : public Texture {
}
VulkanContext *vulkan_;
VulkanTexture *vkTex_;
VulkanTexture *vkTex_ = nullptr;
int mipLevels_;

0 comments on commit ffbdb15

Please sign in to comment.