Skip to content

Commit

Permalink
Assorted paranoia, get rid of an allocation in the audio loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 29, 2024
1 parent 0170e8f commit 9979372
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Common/File/VFS/VFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ uint8_t *VFS::ReadFile(const char *filename, size_t *size) {
if (!fileSystemFound) {
ERROR_LOG(IO, "Missing filesystem for '%s'", filename);
} // Otherwise, the file was just missing. No need to log.
return 0;
return nullptr;
}

bool VFS::GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) {
Expand Down
2 changes: 2 additions & 0 deletions Core/FrameTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void FrameTiming::PostSubmit() {
}

Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval) {
_assert_(draw);

Draw::PresentMode mode = Draw::PresentMode::FIFO;

if (draw->GetDeviceCaps().presentModesSupported & (Draw::PresentMode::IMMEDIATE | Draw::PresentMode::MAILBOX)) {
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/scePsmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class PsmfStream {

psmf->EPMap.clear();
for (u32 i = 0; i < psmf->EPMapEntriesNum; i++) {
// TODO: Should look into validating these offsets. Got a crash report here.
const u8 *const entryAddr = data + psmf->EPMapOffset + EP_MAP_STRIDE * i;
PsmfEntry entry;
entry.EPIndex = entryAddr[0];
Expand Down
7 changes: 3 additions & 4 deletions Core/Reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ namespace Reporting
static std::condition_variable crcCond;
static Path crcFilename;
static std::map<Path, u32> crcResults;
static volatile bool crcPending = false;
static volatile bool crcCancel = false;
static std::atomic<bool> crcPending = false;
static std::atomic<bool> crcCancel = false;
static std::thread crcThread;

static u32 CalculateCRC(BlockDevice *blockDevice, volatile bool *cancel) {
static u32 CalculateCRC(BlockDevice *blockDevice, std::atomic<bool> *cancel) {
auto ga = GetI18NCategory(I18NCat::GAME);

u32 crc = crc32(0, Z_NULL, 0);
Expand Down Expand Up @@ -162,7 +162,6 @@ namespace Reporting
crcResults[crcFilename] = crc;
crcPending = false;
crcCond.notify_one();

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions UI/BackgroundAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ inline int16_t ConvertU8ToI16(uint8_t value) {
}

Sample *Sample::Load(const std::string &path) {
size_t bytes;
size_t bytes = 0;
uint8_t *data = g_VFS.ReadFile(path.c_str(), &bytes);
if (!data) {
if (!data || bytes > 100000000) {
WARN_LOG(AUDIO, "Failed to load sample '%s'", path.c_str());
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ UI::EventReturn GameSettingsScreen::OnChangeBackground(UI::EventParams &e) {
FILE *f = File::OpenCFile(path, "rb");
uint8_t buffer[8];
ImageFileType type = ImageFileType::UNKNOWN;
if (8 == fread(buffer, 1, ARRAY_SIZE(buffer), f)) {
if (f != nullptr && 8 == fread(buffer, 1, ARRAY_SIZE(buffer), f)) {
type = DetectImageFileType(buffer, ARRAY_SIZE(buffer));
}

Expand Down
5 changes: 3 additions & 2 deletions android/jni/OpenSLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <SLES/OpenSLES_Android.h>

#include "Common/Log.h"
#include "Common/StringUtils.h"
#include "OpenSLContext.h"
#include "Core/HLE/sceUsbMic.h"

Expand Down Expand Up @@ -58,7 +57,9 @@ void OpenSLContext::BqPlayerCallback(SLAndroidSimpleBufferQueueItf bq) {
memset(buffer[curBuffer] + renderedFrames * 2, 0, byteCount);
}
SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeInBytes);
CheckResult(result, StringFromFormat("Failed to enqueue: %d %d", renderedFrames, sizeInBytes).c_str());

// TODO: get rid of this snprintf too
CheckResult(result, "Failed to enqueue");
// Comment from sample code:
// the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
// which for this code example would indicate a programming error
Expand Down
15 changes: 8 additions & 7 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,13 +1162,11 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendRequestResult(JNIEn
}
}

void LockedNativeUpdateRender() {
std::lock_guard<std::mutex> renderGuard(renderLock);
NativeFrame(graphicsContext);
}

void UpdateRunLoopAndroid(JNIEnv *env) {
LockedNativeUpdateRender();
{
std::lock_guard<std::mutex> renderGuard(renderLock);
NativeFrame(graphicsContext);
}

std::lock_guard<std::mutex> guard(frameCommandLock);
if (!nativeActivity) {
Expand Down Expand Up @@ -1639,7 +1637,10 @@ static void VulkanEmuThread(ANativeWindow *wnd) {
renderer_inited = true;

while (!exitRenderLoop) {
LockedNativeUpdateRender();
{
std::lock_guard<std::mutex> renderGuard(renderLock);
NativeFrame(graphicsContext);
}
ProcessFrameCommands(env);
}
INFO_LOG(G3D, "Leaving Vulkan main loop.");
Expand Down

0 comments on commit 9979372

Please sign in to comment.