diff --git a/Common/Data/Collections/FastVec.h b/Common/Data/Collections/FastVec.h index 6622cbdeb8da..9e31d2f031ad 100644 --- a/Common/Data/Collections/FastVec.h +++ b/Common/Data/Collections/FastVec.h @@ -8,9 +8,7 @@ #include #include -#ifdef _DEBUG #include "Common/Log.h" -#endif template class FastVec { @@ -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_); } @@ -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); @@ -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; diff --git a/Common/GPU/OpenGL/GLMemory.cpp b/Common/GPU/OpenGL/GLMemory.cpp index 4f93c6a79276..92e6052fab5d 100644 --- a/Common/GPU/OpenGL/GLMemory.cpp +++ b/Common/GPU/OpenGL/GLMemory.cpp @@ -203,7 +203,6 @@ void GLPushBuffer::Defragment() { info.localMemory = nullptr; } } - return; } diff --git a/Common/GPU/Vulkan/VulkanImage.cpp b/Common/GPU/Vulkan/VulkanImage.cpp index ebe6248bba6b..08d79a380d39 100644 --- a/Common/GPU/Vulkan/VulkanImage.cpp +++ b/Common/GPU/Vulkan/VulkanImage.cpp @@ -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; @@ -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_); } diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 8bfb9d0834b8..795fbe5c2c86 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -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 }; diff --git a/Common/UI/ScrollView.cpp b/Common/UI/ScrollView.cpp index 6adbeca05c6d..728bbc72782f 100644 --- a/Common/UI/ScrollView.cpp +++ b/Common/UI/ScrollView.cpp @@ -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; } @@ -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; @@ -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; diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index a40f333e6dbf..7a54ff66f0ef 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -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_) { diff --git a/Core/FileSystems/BlockDevices.h b/Core/FileSystems/BlockDevices.h index 295f29a57601..ac3e1de04391 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -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; }; diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 6f2f5fe94553..fe0e8a54de6b 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -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); diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 9b43750236de..d78b59033ff1 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -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 guard(ctrlMutex); ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaledX; ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaledY; diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index 6a9ee882b816..25dd008ba02b 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -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); diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 6c88b29a37ac..2e0b69b6c839 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -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()) { diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index cac73b76f516..f3d26bade633 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -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", ¶mSFOcontents, 0)) { + if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, nullptr)) { std::lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); info_->ParseParamSFO(); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index be909da8cb87..54a6f04d99c4 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -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(); - 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); @@ -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 } diff --git a/android/src/org/ppsspp/ppsspp/MogaHack.java b/android/src/org/ppsspp/ppsspp/MogaHack.java index 745a1fa8c869..fdced81755d0 100644 --- a/android/src/org/ppsspp/ppsspp/MogaHack.java +++ b/android/src/org/ppsspp/ppsspp/MogaHack.java @@ -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 @@ -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) { @@ -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); } } }