Merge pull request #12122 from unknownbrackets/ui-crash

Avoid crash on dead UI events and bad save state decompress
This commit is contained in:
Henrik Rydgård 2019-06-23 22:24:12 +02:00 committed by GitHub
commit 79f0560619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 8 deletions

View File

@ -249,19 +249,27 @@ CChunkFileReader::Error CChunkFileReader::LoadFile(const std::string &filename,
return ERROR_BAD_FILE;
}
_buffer = buffer;
if (header.Compress) {
u8 *uncomp_buffer = new u8[header.UncompressedSize];
size_t uncomp_size = header.UncompressedSize;
snappy_uncompress((const char *)buffer, sz, (char *)uncomp_buffer, &uncomp_size);
auto status = snappy_uncompress((const char *)buffer, sz, (char *)uncomp_buffer, &uncomp_size);
if (status != SNAPPY_OK) {
ERROR_LOG(SAVESTATE, "ChunkReader: Failed to decompress file");
delete [] uncomp_buffer;
delete [] buffer;
return ERROR_BAD_FILE;
}
if ((u32)uncomp_size != header.UncompressedSize) {
ERROR_LOG(SAVESTATE, "Size mismatch: file: %u calc: %u", header.UncompressedSize, (u32)uncomp_size);
delete [] uncomp_buffer;
delete [] buffer;
return ERROR_BAD_FILE;
}
_buffer = uncomp_buffer;
sz = uncomp_size;
delete [] buffer;
} else {
_buffer = buffer;
}
if (header.GitVersion[31]) {

View File

@ -60,9 +60,22 @@ void DispatchEvents() {
}
void RemoveQueuedEvents(View *v) {
for (size_t i = 0; i < g_dispatchQueue.size(); i++) {
if (g_dispatchQueue[i].params.v == v)
g_dispatchQueue.erase(g_dispatchQueue.begin() + i);
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->params.v == v) {
it = g_dispatchQueue.erase(it);
} else {
++it;
}
}
}
void RemoveQueuedEvents(Event *e) {
for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) {
if (it->e == e) {
it = g_dispatchQueue.erase(it);
} else {
++it;
}
}
}
@ -157,6 +170,11 @@ EventReturn Event::Dispatch(EventParams &e) {
return UI::EVENT_SKIPPED;
}
Event::~Event() {
handlers_.clear();
RemoveQueuedEvents(this);
}
View::~View() {
if (HasFocus())
SetFocusedView(0);

View File

@ -240,9 +240,7 @@ struct HandlerRegistration {
class Event {
public:
Event() {}
~Event() {
handlers_.clear();
}
~Event();
// Call this from input thread or whatever, it doesn't matter
void Trigger(EventParams &e);
// Call this from UI thread