Skip to content

Commit

Permalink
Merge pull request #18800 from hrydgard/last-minute-fixes
Browse files Browse the repository at this point in the history
Even more checks and fixes
  • Loading branch information
hrydgard committed Jan 31, 2024
2 parents d7a250d + ce5f157 commit 14cd094
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 54 deletions.
6 changes: 4 additions & 2 deletions Common/Data/Collections/FastVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <cstdlib>
#include <cstring>

#ifdef _DEBUG
#include "Common/Log.h"
#endif

template<class T>
class FastVec {
Expand All @@ -19,6 +17,7 @@ class FastVec {
FastVec(size_t initialCapacity) {
capacity_ = initialCapacity;
data_ = (T *)malloc(initialCapacity * sizeof(T));
_assert_(data_ != nullptr);
}
~FastVec() { if (data_) free(data_); }

Expand Down Expand Up @@ -157,6 +156,7 @@ class FastVec {
return;
T *oldData = data_;
data_ = (T *)malloc(sizeof(T) * newCapacity);
_assert_msg_(data_ != nullptr, "%d", (int)newCapacity);
if (capacity_ != 0) {
memcpy(data_, oldData, sizeof(T) * size_);
free(oldData);
Expand All @@ -165,6 +165,8 @@ class FastVec {
}

void ExtendByOne() {
// We don't really extend capacity by one though - instead we use
// the usual doubling amortization.
size_t newCapacity = capacity_ * 2;
if (newCapacity < 16) {
newCapacity = 16;
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/OpenGL/GLMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ void GLPushBuffer::Defragment() {
info.localMemory = nullptr;
}
}

return;
}

Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/Vulkan/VulkanImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool VulkanTexture::CreateDirect(VkCommandBuffer cmd, int w, int h, int depth, i
res = vkCreateImageView(vulkan_->GetDevice(), &view_info, NULL, &view_);
if (res != VK_SUCCESS) {
ERROR_LOG(G3D, "vkCreateImageView failed: %s. Destroying image.", VulkanResultToString(res));
_assert_(res == VK_ERROR_OUT_OF_HOST_MEMORY || res == VK_ERROR_OUT_OF_DEVICE_MEMORY || res == VK_ERROR_TOO_MANY_OBJECTS);
_assert_msg_(res == VK_ERROR_OUT_OF_HOST_MEMORY || res == VK_ERROR_OUT_OF_DEVICE_MEMORY || res == VK_ERROR_TOO_MANY_OBJECTS, "%d", (int)res);
vmaDestroyImage(vulkan_->Allocator(), image_, allocation_);
view_ = VK_NULL_HANDLE;
image_ = VK_NULL_HANDLE;
Expand All @@ -152,7 +152,7 @@ bool VulkanTexture::CreateDirect(VkCommandBuffer cmd, int w, int h, int depth, i
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
res = vkCreateImageView(vulkan_->GetDevice(), &view_info, NULL, &arrayView_);
// Assume that if the above view creation succeeded, so will this.
_assert_(res == VK_SUCCESS);
_assert_msg_(res == VK_SUCCESS, "View creation failed: %d", (int)res);
vulkan_->SetDebugName(arrayView_, VK_OBJECT_TYPE_IMAGE_VIEW, tag_);
}

Expand Down
10 changes: 8 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,15 @@ void VulkanRenderManager::BlitFramebuffer(VKRFramebuffer *src, VkRect2D srcRect,
EndCurRenderStep();

// Sanity check. Added an assert to try to gather more info.
// Got this assert in NPJH50443 FINAL FANTASY TYPE-0, but pretty rare. Moving back to debug assert.
if (aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
_assert_msg_(src->depth.image != VK_NULL_HANDLE, "%s", src->Tag());
_assert_msg_(dst->depth.image != VK_NULL_HANDLE, "%s", dst->Tag());
_dbg_assert_msg_(src->depth.image != VK_NULL_HANDLE, "%s", src->Tag());
_dbg_assert_msg_(dst->depth.image != VK_NULL_HANDLE, "%s", dst->Tag());

if (!src->depth.image || !dst->depth.image) {
// Something has gone wrong, but let's try to stumble along.
return;
}
}

VKRStep *step = new VKRStep{ VKRStepType::BLIT };
Expand Down
11 changes: 7 additions & 4 deletions Common/UI/ScrollView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ bool ScrollView::Touch(const TouchInput &input) {
if (orientation_ == ORIENT_VERTICAL) {
Bob bob = ComputeBob();
float internalY = input.y - bounds_.y;
draggingBob_ = internalY >= bob.offset && internalY <= bob.offset + bob.size && input.x >= bounds_.x2() - 20.0f;
float bobMargin = 3.0f; // Add some extra margin for the touch.
draggingBob_ = internalY >= bob.offset - bobMargin && internalY <= bob.offset + bob.size + bobMargin && input.x >= bounds_.x2() - 20.0f;
barDragStart_ = bob.offset;
barDragOffset_ = internalY - bob.offset;
}
Expand All @@ -165,11 +166,13 @@ bool ScrollView::Touch(const TouchInput &input) {
draggingBob_ = false;
}

// We modify the input2 we send to children, so we can cancel drags if we start scrolling, and stuff like that.
TouchInput input2;
if (CanScroll()) {
if (draggingBob_) {
input2 = input;
// Skip the gesture, do calculations directly.
// Cancel any drags/holds on the children instantly to avoid accidental click-throughs.
input2.flags = TOUCH_UP | TOUCH_CANCEL;
// Skip the gesture manager, do calculations directly.
// Might switch to the gesture later.
Bob bob = ComputeBob();
float internalY = input.y - bounds_.y;
Expand Down Expand Up @@ -216,7 +219,7 @@ ScrollView::Bob ScrollView::ComputeBob() const {

if (ratio < 1.0f && scrollMax > 0.0f) {
bob.show = true;
bob.thickness = draggingBob_ ? 15.0f : 5.0f;
bob.thickness = draggingBob_ ? 15.0f : 6.0f;
bob.size = ratio * bounds_.h;
bob.offset = (HardClampedScrollPos(scrollPos_) / scrollMax) * (bounds_.h - bob.size);
bob.scrollMax = scrollMax;
Expand Down
12 changes: 7 additions & 5 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,13 @@ void Choice::Draw(UIContext &dc) {

if (image_.isValid()) {
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(image_);
_dbg_assert_(image);
paddingX += image->w + 6;
availWidth -= image->w + 6;
// TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now)
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_LEFT | ALIGN_VCENTER);
if (image) {
_dbg_assert_(image);
paddingX += image->w + 6;
availWidth -= image->w + 6;
// TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now)
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_LEFT | ALIGN_VCENTER);
}
}

if (centered_) {
Expand Down
20 changes: 10 additions & 10 deletions Core/FileSystems/BlockDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ class CISOFileBlockDevice : public BlockDevice {
bool IsDisc() const override { return true; }

private:
u32 *index;
u8 *readBuffer;
u8 *zlibBuffer;
u32 zlibBufferFrame;
u8 indexShift;
u8 blockShift;
u32 frameSize;
u32 numBlocks;
u32 numFrames;
int ver_;
u32 *index = nullptr;
u8 *readBuffer = nullptr;
u8 *zlibBuffer = nullptr;
u32 zlibBufferFrame = 0;
u8 indexShift = 0;
u8 blockShift = 0;
u32 frameSize = 0;
u32 numBlocks = 0;
u32 numFrames = 0;
int ver_ = 0;
};


Expand Down
5 changes: 4 additions & 1 deletion Core/HLE/sceAtrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,10 @@ int Atrac::Analyze(u32 addr, u32 size) {
}
int checkNumLoops = Memory::Read_U32(first_.addr + offset + 28);
if (checkNumLoops != 0 && chunkSize < 36 + 20) {
return hleReportError(ME, ATRAC_ERROR_UNKNOWN_FORMAT, "smpl chunk too small for loop (%d)", chunkSize);
return hleReportError(ME, ATRAC_ERROR_UNKNOWN_FORMAT, "smpl chunk too small for loop (%d, %d)", checkNumLoops, chunkSize);
}
if (checkNumLoops < 0) {
return hleReportError(ME, ATRAC_ERROR_UNKNOWN_FORMAT, "bad checkNumLoops (%d)", checkNumLoops);
}

loopinfo_.resize(checkNumLoops);
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void __CtrlSetAnalogXY(int stick, float x, float y)
u8 scaledX = clamp_u8((int)ceilf(x * 127.5f + 127.5f));
// TODO: We might have too many negations of Y...
u8 scaledY = clamp_u8((int)ceilf(-y * 127.5f + 127.5f));

std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaledX;
ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaledY;
Expand Down
2 changes: 1 addition & 1 deletion Core/HW/SasAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class SasInstance {
private:
SasReverb reverb_;
int grainSize = 0;
int16_t mixTemp_[PSP_SAS_MAX_GRAIN * 4 + 2 + 8]; // some extra margin for very high pitches.
int16_t mixTemp_[PSP_SAS_MAX_GRAIN * 4 + 2 + 16]; // some extra margin for very high pitches.
};

const char *ADSRCurveModeAsString(SasADSRCurveMode mode);
3 changes: 2 additions & 1 deletion Core/Util/PPGeDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,12 @@ static bool HasTextDrawer() {
return textDrawer != nullptr;
}

static std::string PPGeSanitizeText(const std::string &text) {
static std::string PPGeSanitizeText(std::string_view text) {
return SanitizeUTF8(text);
}

void PPGeMeasureText(float *w, float *h, const char *text, float scale, int WrapType, int wrapWidth) {
_dbg_assert_(text);
std::string s = PPGeSanitizeText(text);

if (HasTextDrawer()) {
Expand Down
2 changes: 1 addition & 1 deletion UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class GameInfoWorkItem : public Task {
// Alright, let's fetch the PARAM.SFO.
if (flags_ & GameInfoFlags::PARAM_SFO) {
std::string paramSFOcontents;
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, 0)) {
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, nullptr)) {
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();
Expand Down
13 changes: 8 additions & 5 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,12 @@ void SettingInfoMessage::Show(const std::string &text, const UI::View *refView)
if (refView) {
Bounds b = refView->GetBounds();
const UI::AnchorLayoutParams *lp = GetLayoutParams()->As<UI::AnchorLayoutParams>();
if (cutOffY_ != -1.0f && b.y >= cutOffY_) {
ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, 80.0f, lp->right, lp->bottom, lp->center));
} else {
ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, g_display.dp_yres - 80.0f - 40.0f, lp->right, lp->bottom, lp->center));
if (lp) {
if (cutOffY_ != -1.0f && b.y >= cutOffY_) {
ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, 80.0f, lp->right, lp->bottom, lp->center));
} else {
ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, g_display.dp_yres - 80.0f - 40.0f, lp->right, lp->bottom, lp->center));
}
}
}
text_->SetText(text);
Expand Down Expand Up @@ -1089,7 +1091,8 @@ void SettingInfoMessage::Draw(UIContext &dc) {
dc.FillRect(style.background, bounds_);
}

text_->SetTextColor(whiteAlpha(alpha));
uint32_t textColor = colorAlpha(dc.GetTheme().itemStyle.fgColor, alpha);
text_->SetTextColor(textColor);
ViewGroup::Draw(dc);
showing_ = sinceShow <= timeToShow; // Don't consider fade time
}
Expand Down
40 changes: 21 additions & 19 deletions android/src/org/ppsspp/ppsspp/MogaHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,23 @@
*/
public class MogaHack {
public static void init(Controller controller, Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
controller.init();
return;
}
try {
boolean mIsBound = false;
java.lang.reflect.Field fIsBound = null;
android.content.ServiceConnection mServiceConnection = null;
java.lang.reflect.Field fServiceConnection = null;

try {
Class<?> cMogaController = controller.getClass();
fIsBound = cMogaController.getDeclaredField("mIsBound");
fIsBound.setAccessible(true);
mIsBound = fIsBound.getBoolean(controller);
fServiceConnection = cMogaController.getDeclaredField("mServiceConnection");
fServiceConnection.setAccessible(true);
mServiceConnection = (android.content.ServiceConnection) fServiceConnection.get(controller);
} catch (NoSuchFieldException e) {
Log.e("MogaHack", "MOGA Lollipop Hack NoSuchFieldException (get)", e);
} catch (IllegalAccessException e) {
Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (get)", e);
} catch (IllegalArgumentException e) {
Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (get)", e);
}
Class<?> cMogaController = controller.getClass();
fIsBound = cMogaController.getDeclaredField("mIsBound");
fIsBound.setAccessible(true);
mIsBound = fIsBound.getBoolean(controller);
fServiceConnection = cMogaController.getDeclaredField("mServiceConnection");
fServiceConnection.setAccessible(true);
mServiceConnection = (android.content.ServiceConnection) fServiceConnection.get(controller);

if ((!mIsBound) && (mServiceConnection != null)) {
// Convert implicit intent to explicit intent, see http://stackoverflow.com/a/26318757
Expand All @@ -83,7 +79,7 @@ public static void init(Controller controller, Context context) {

// Start the service explicitly
context.startService(intent);
context.bindService(intent, mServiceConnection, 1);
context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE );
try {
fIsBound.setBoolean(controller, true);
} catch (IllegalAccessException e) {
Expand All @@ -92,8 +88,14 @@ public static void init(Controller controller, Context context) {
Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (set)", e);
}
}
} else {
controller.init();
} catch (NoSuchFieldException e) {
Log.e("MogaHack", "MOGA Lollipop Hack NoSuchFieldException (get)", e);
} catch (IllegalAccessException e) {
Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (get)", e);
} catch (IllegalArgumentException e) {
Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (get)", e);
} catch (Exception e) {
Log.e("MogaHack", "MOGA", e);
}
}
}

0 comments on commit 14cd094

Please sign in to comment.