Fixed leak of event objects on OS X.

This commit is contained in:
crs 2004-12-29 17:06:00 +00:00
parent 01fe5fb0a3
commit f0a5d3162e
2 changed files with 13 additions and 16 deletions

View File

@ -34,7 +34,10 @@ COSXEventQueueBuffer::COSXEventQueueBuffer() :
COSXEventQueueBuffer::~COSXEventQueueBuffer()
{
setOSXEvent(NULL);
// release the last event
if (m_event != NULL) {
ReleaseEvent(m_event);
}
}
void
@ -47,10 +50,16 @@ COSXEventQueueBuffer::waitForEvent(double timeout)
IEventQueueBuffer::Type
COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
{
EventRef carbonEvent = NULL;
OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &carbonEvent);
setOSXEvent(carbonEvent);
// release the previous event
if (m_event != NULL) {
ReleaseEvent(m_event);
m_event = NULL;
}
// get the next event
OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &m_event);
// handle the event
if (error == eventLoopQuitErr) {
event = CEvent(CEvent::kQuit);
return kSystem;
@ -113,12 +122,3 @@ COSXEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
{
delete timer;
}
void
COSXEventQueueBuffer::setOSXEvent(EventRef event)
{
if (m_event != NULL) {
ReleaseEvent(m_event);
}
m_event = RetainEvent(event);
}

View File

@ -33,9 +33,6 @@ public:
newTimer(double duration, bool oneShot) const;
virtual void deleteTimer(CEventQueueTimer*) const;
protected:
void setOSXEvent(EventRef event);
private:
EventRef m_event;
};