Skip to content

Commit

Permalink
SoftGPU: Fix crash when stride is 0.
Browse files Browse the repository at this point in the history
This happens in Star Ocean 1.
  • Loading branch information
unknownbrackets committed Nov 12, 2017
1 parent 9f77d48 commit ffbdb15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 12 additions & 3 deletions GPU/Software/SoftGpu.cpp
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions ext/native/thin3d/thin3d_vulkan.cpp
Expand Up @@ -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() {
Expand All @@ -336,7 +337,7 @@ class VKTexture : public Texture {
}

VulkanContext *vulkan_;
VulkanTexture *vkTex_;
VulkanTexture *vkTex_ = nullptr;

int mipLevels_;

Expand Down

0 comments on commit ffbdb15

Please sign in to comment.