Skip to content
Permalink
Browse files

Merge pull request #12122 from unknownbrackets/ui-crash

Avoid crash on dead UI events and bad save state decompress
  • Loading branch information...
hrydgard committed Jun 23, 2019
2 parents 3a98a5d + eaba867 commit 79f056061911fa8822c66ecf81445fc233466688
Showing with 32 additions and 8 deletions.
  1. +10 −2 Common/ChunkFile.cpp
  2. +21 −3 ext/native/ui/view.cpp
  3. +1 −3 ext/native/ui/view.h
@@ -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]) {
@@ -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);
@@ -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

0 comments on commit 79f0560

Please sign in to comment.
You can’t perform that action at this time.