Merge pull request #12366 from hrydgard/crash-fixes-1.9

A first round of crash fixes from 1.9 crash reports
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2019-09-28 00:20:58 +02:00
commit 25634d2df2
11 files changed
+103 -49

No files matched your search

+33 -8
View File
@@ -692,41 +692,66 @@ static u32 sysclib_memcpy(u32 dst, u32 src, u32 size) {
static u32 sysclib_strcat(u32 dst, u32 src) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcat(dest=%08x, src=%08x)", dst, src);
strcat((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(src)) {
strcat((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
}
return dst;
}
static int sysclib_strcmp(u32 dst, u32 src) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcmp(dest=%08x, src=%08x)", dst, src);
return strcmp((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(src)) {
return strcmp((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
} else {
// What to do? Crash, probably.
return 0;
}
}
static u32 sysclib_strcpy(u32 dst, u32 src) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strcpy(dest=%08x, src=%08x)", dst, src);
strcpy((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(src)) {
strcpy((char *)Memory::GetPointer(dst), (char *)Memory::GetPointer(src));
}
return dst;
}
static u32 sysclib_strlen(u32 src) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strlen(src=%08x)", src);
return (u32)strlen(Memory::GetCharPointer(src));
if (Memory::IsValidAddress(src)) {
return (u32)strlen(Memory::GetCharPointer(src));
} else {
// What to do? Crash, probably.
return 0;
}
}
static int sysclib_memcmp(u32 dst, u32 src, u32 size) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_memcmp(dest=%08x, src=%08x, size=%i)", dst, src, size);
return memcmp(Memory::GetCharPointer(dst), Memory::GetCharPointer(src), size);
if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) {
return memcmp(Memory::GetCharPointer(dst), Memory::GetCharPointer(src), size);
} else {
// What to do? Crash, probably.
return 0;
}
}
static int sysclib_sprintf(u32 dst, u32 fmt) {
ERROR_LOG(SCEKERNEL, "Unimpl sysclib_sprintf(dest=%08x, src=%08x)", dst, fmt);
// TODO
return sprintf((char *)Memory::GetPointer(dst), "%s", Memory::GetCharPointer(fmt));
if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(fmt)) {
// TODO: Properly use the format string with more parameters.
return sprintf((char *)Memory::GetPointer(dst), "%s", Memory::GetCharPointer(fmt));
} else {
// What to do? Crash, probably.
return 0;
}
}
static u32 sysclib_memset(u32 destAddr, int data, int size) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_memset(dest=%08x, data=%d ,size=%d)", destAddr, data, size);
if (Memory::IsValidAddress(destAddr))
if (Memory::IsValidRange(destAddr, size)) {
memset(Memory::GetPointer(destAddr), data, size);
}
return 0;
}
+2 -2
View File
@@ -630,9 +630,9 @@ namespace SaveState
// Okay, first, let's give the rewind state a shot - maybe we can at least not reset entirely.
// Even if this was a rewind, maybe we can still load a previous one.
CChunkFileReader::Error result;
do
do {
result = rewindStates.Restore();
while (result == CChunkFileReader::ERROR_BROKEN_STATE);
} while (result == CChunkFileReader::ERROR_BROKEN_STATE);
if (result == CChunkFileReader::ERROR_NONE) {
return true;
+5
View File
@@ -431,6 +431,11 @@ bool GameManager::ExtractFile(struct zip *z, int file_index, std::string outFile
}
zip_file *zf = zip_fopen_index(z, file_index, 0);
if (!zf) {
ERROR_LOG(HLE, "Failed to open file by index (%d) (%s)", file_index, outFilename.c_str());
return false;
}
FILE *f = File::OpenCFile(outFilename, "wb");
if (f) {
size_t pos = 0;
+1 -1
View File
@@ -1219,7 +1219,6 @@ void TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETextureForm
case GE_CMODE_16BIT_ABGR5551:
case GE_CMODE_16BIT_ABGR4444:
{
const u16 *clut = GetCurrentClut<u16>() + clutSharingOffset;
if (clutAlphaLinear_ && mipmapShareClut && !expandTo32bit) {
// Here, reverseColors means the CLUT is already reversed.
if (reverseColors) {
@@ -1232,6 +1231,7 @@ void TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETextureForm
}
}
} else {
const u16 *clut = GetCurrentClut<u16>() + clutSharingOffset;
if (expandTo32bit && !reverseColors) {
// We simply expand the CLUT to 32-bit, then we deindex as usual. Probably the fastest way.
ConvertFormatToRGBA8888(clutformat, expandClut_, clut, 16);
+33 -26
View File
@@ -223,7 +223,7 @@ private:
SimpleAudio *decoder_ = nullptr;
};
static std::mutex bgMutex;
static std::mutex g_bgMutex;
static std::string bgGamePath;
static int playbackOffset;
static AT3PlusReader *at3Reader;
@@ -251,7 +251,7 @@ static void ClearBackgroundAudio(bool hard) {
void SetBackgroundAudioGame(const std::string &path) {
time_update();
std::lock_guard<std::mutex> lock(bgMutex);
std::lock_guard<std::mutex> lock(g_bgMutex);
if (path == bgGamePath) {
// Do nothing
return;
@@ -272,7 +272,7 @@ void SetBackgroundAudioGame(const std::string &path) {
int PlayBackgroundAudio() {
time_update();
std::lock_guard<std::mutex> lock(bgMutex);
std::lock_guard<std::mutex> lock(g_bgMutex);
// Immediately stop the sound if it is turned off while playing.
if (!g_Config.bEnableSound) {
@@ -281,29 +281,6 @@ int PlayBackgroundAudio() {
return 0;
}
// If there's a game, and some time has passed since the selected game
// last changed... (to prevent crazy amount of reads when skipping through a list)
if (!at3Reader && bgGamePath.size() && (time_now_d() - gameLastChanged > 0.5)) {
// Grab some audio from the current game and play it.
if (!g_gameInfoCache)
return 0; // race condition?
std::shared_ptr<GameInfo> gameInfo = g_gameInfoCache->GetInfo(NULL, bgGamePath, GAMEINFO_WANTSND);
if (!gameInfo)
return 0;
if (gameInfo->pending) {
// Should try again shortly..
return 0;
}
if (gameInfo->sndFileData.size()) {
const std::string &data = gameInfo->sndFileData;
at3Reader = new AT3PlusReader(data);
lastPlaybackTime = 0.0;
}
}
double now = time_now();
if (at3Reader) {
int sz = lastPlaybackTime <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime) * 44100);
@@ -335,3 +312,33 @@ int PlayBackgroundAudio() {
return 0;
}
// Stuff that should be on the UI thread only, like anything to do with
// g_gameInfoCache.
void UpdateBackgroundAudio() {
// If there's a game, and some time has passed since the selected game
// last changed... (to prevent crazy amount of reads when skipping through a list)
if (bgGamePath.size() && (time_now_d() - gameLastChanged > 0.5)) {
std::lock_guard<std::mutex> lock(g_bgMutex);
if (!at3Reader) {
// Grab some audio from the current game and play it.
if (!g_gameInfoCache)
return;
std::shared_ptr<GameInfo> gameInfo = g_gameInfoCache->GetInfo(NULL, bgGamePath, GAMEINFO_WANTSND);
if (!gameInfo)
return;
if (gameInfo->pending) {
// Should try again shortly..
return;
}
if (gameInfo->sndFileData.size()) {
const std::string &data = gameInfo->sndFileData;
at3Reader = new AT3PlusReader(data);
lastPlaybackTime = 0.0;
}
}
}
}
+1
View File
@@ -4,3 +4,4 @@
void SetBackgroundAudioGame(const std::string &path);
int PlayBackgroundAudio();
void UpdateBackgroundAudio();
+1
View File
@@ -734,6 +734,7 @@ void GameInfoCache::WaitUntilDone(std::shared_ptr<GameInfo> &info) {
// Runs on the main thread. Only call from render() and similar, not update()!
// Can also be called from the audio thread for menu background music.
std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const std::string &gamePath, int wantFlags) {
std::shared_ptr<GameInfo> info;
-8
View File
@@ -61,12 +61,6 @@ class FileLoader;
enum class IdentifiedFileType;
struct GameInfoTex {
GameInfoTex() {}
~GameInfoTex() {
if (texture) {
ELOG("LEAKED GameInfoTex");
}
}
std::string data;
std::unique_ptr<ManagedTexture> texture;
// The time at which the Icon and the BG were loaded.
@@ -81,8 +75,6 @@ struct GameInfoTex {
}
texture.reset(nullptr);
}
private:
DISALLOW_COPY_AND_ASSIGN(GameInfoTex);
};
class GameInfo {
+6 -3
View File
@@ -110,12 +110,15 @@ void InstallZipScreen::update() {
using namespace UI;
if (g_GameManager.GetState() != GameManagerState::IDLE) {
progressBar_->SetVisibility(V_VISIBLE);
progressBar_->SetProgress(g_GameManager.GetCurrentInstallProgressPercentage());
if (progressBar_) {
progressBar_->SetVisibility(V_VISIBLE);
progressBar_->SetProgress(g_GameManager.GetCurrentInstallProgressPercentage());
}
backChoice_->SetEnabled(false);
} else {
if (progressBar_)
if (progressBar_) {
progressBar_->SetVisibility(V_GONE);
}
backChoice_->SetEnabled(true);
std::string err = g_GameManager.GetInstallError();
if (!err.empty()) {
+7
View File
@@ -780,6 +780,7 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
using namespace Draw;
Core_SetGraphicsContext(graphicsContext);
g_draw = graphicsContext->GetDrawContext();
_assert_msg_(G3D, g_draw->GetVshaderPreset(VS_COLOR_2D) != nullptr, "Failed to compile presets");
_assert_msg_(G3D, g_draw, "No draw context available!");
ui_draw2d.SetAtlas(&ui_atlas);
@@ -958,6 +959,12 @@ void RenderOverlays(UIContext *dc, void *userdata) {
void NativeRender(GraphicsContext *graphicsContext) {
g_GameManager.Update();
if (GetUIState() != UISTATE_INGAME) {
// Note: We do this from NativeRender so that the graphics context is
// guaranteed valid, to be safe - g_gameInfoCache messes around with textures.
UpdateBackgroundAudio();
}
float xres = dp_xres;
float yres = dp_yres;
+14 -1
View File
@@ -71,6 +71,7 @@ bool OpenSLContext::Init() {
result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
if (result != SL_RESULT_SUCCESS) {
ELOG("OpenSL ES: Failed to create the engine: %d", (int)result);
engineObject = nullptr;
return false;
}
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
@@ -78,7 +79,13 @@ bool OpenSLContext::Init() {
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
assert(SL_RESULT_SUCCESS == result);
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, 0, 0);
assert(SL_RESULT_SUCCESS == result);
if (result != SL_RESULT_SUCCESS) {
ELOG("OpenSL ES: Failed to create output mix: %d", (int)result);
(*engineObject)->Destroy(engineObject);
engineEngine = nullptr;
engineObject = nullptr;
return false;
}
result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
assert(SL_RESULT_SUCCESS == result);
@@ -108,7 +115,13 @@ bool OpenSLContext::Init() {
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 2, ids, req);
if (result != SL_RESULT_SUCCESS) {
ELOG("OpenSL ES: CreateAudioPlayer failed: %d", (int)result);
(*outputMixObject)->Destroy(outputMixObject);
outputMixObject = nullptr;
// Should really tear everything down here. Sigh.
(*engineObject)->Destroy(engineObject);
engineEngine = nullptr;
engineObject = nullptr;
return false;
}