Fix crash double-clicking a file on MacOS X Finder

This commit is contained in:
David Capello 2015-08-06 17:36:41 -03:00
parent 70db3da8be
commit 14601dd94f
6 changed files with 36 additions and 33 deletions

View File

@ -14,7 +14,7 @@
#include "she/alleg4/alleg_display.h"
#include "she/event.h"
#include "she/system.h"
#include "she/event_queue.h"
void* get_osx_window()
{

View File

@ -11,7 +11,7 @@
#include "she/alleg4/alleg_display.h"
#include "she/display.h"
#include "she/event.h"
#include "she/system.h"
#include "she/event_queue.h"
#include <allegro.h>

View File

@ -12,7 +12,7 @@
#include "she/clock.h"
#include "she/display.h"
#include "she/event.h"
#include "she/system.h"
#include "she/event_queue.h"
#include <allegro.h>

View File

@ -70,22 +70,7 @@ namespace she {
class Alleg4EventQueue : public EventQueue {
public:
Alleg4EventQueue() {
clock_init();
display_events_init();
#ifdef USE_KEY_POLLER
key_poller_init();
#endif
#ifdef USE_MOUSE_POLLER
mouse_poller_init();
#endif
}
~Alleg4EventQueue() {
clock_exit();
}
static Alleg4EventQueue g_queue;
void getEvent(Event& event, bool canWait) override {
(void)canWait; // Ignore this parameter
@ -115,6 +100,12 @@ private:
base::concurrent_queue<Event> m_events;
};
Alleg4EventQueue g_queue;
EventQueue* EventQueue::instance() {
return &g_queue;
}
class Alleg4System : public CommonSystem {
public:
Alleg4System()
@ -131,16 +122,25 @@ public:
// Register PNG as a supported bitmap type
register_bitmap_file_type("png", load_png, save_png);
// Init event sources
clock_init();
display_events_init();
#ifdef USE_KEY_POLLER
key_poller_init();
#endif
#ifdef USE_MOUSE_POLLER
mouse_poller_init();
#endif
g_instance = this;
m_queue.reset(new Alleg4EventQueue);
}
~Alleg4System() {
m_queue.reset();
g_instance = nullptr;
clock_exit();
remove_timer();
allegro_exit();
g_instance = nullptr;
}
void dispose() override {
@ -151,8 +151,8 @@ public:
return (Capabilities)(kCanResizeDisplayCapability);
}
EventQueue* eventQueue() override {
return m_queue;
EventQueue* eventQueue() override { // TODO remove this function
return EventQueue::instance();
}
Display* defaultDisplay() override {
@ -188,9 +188,6 @@ public:
set_color_conversion(old_color_conv);
return sur;
}
private:
base::UniquePtr<Alleg4EventQueue> m_queue;
};
System* create_system() {

View File

@ -17,8 +17,18 @@ namespace she {
virtual ~EventQueue() { }
virtual void getEvent(Event& ev, bool canWait) = 0;
virtual void queueEvent(const Event& ev) = 0;
// On MacOS X we need the EventQueue before the creation of the
// System. E.g. when we double-click a file an Event to open that
// file is queued in application:openFile:, code which is executed
// before the user's main() code.
static EventQueue* instance();
};
inline void queue_event(const Event& ev) {
EventQueue::instance()->queueEvent(ev);
}
} // namespace she
#endif

View File

@ -9,7 +9,6 @@
#pragma once
#include "she/capabilities.h"
#include "she/event_queue.h"
#include <stdexcept>
@ -17,6 +16,7 @@ namespace she {
class Clipboard;
class Display;
class EventQueue;
class Font;
class Logger;
class NativeDialogs;
@ -49,10 +49,6 @@ namespace she {
System* create_system();
System* instance();
inline void queue_event(const Event& ev) {
instance()->eventQueue()->queueEvent(ev);
}
} // namespace she
#endif