Skip to content

Commit

Permalink
qtcollider: close all windows earlier in class library recompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jleben committed May 4, 2012
1 parent 382cecc commit 9142ba9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
42 changes: 42 additions & 0 deletions QtCollider/LanguageClient.cpp
Expand Up @@ -22,6 +22,10 @@
#include "LanguageClient.h"
#include "QcApplication.h"
#include "QtCollider.h"
#include "QObjectProxy.h"

#include <PyrKernel.h>
#include <PyrLexer.h>

#include <qmath.h>

Expand Down Expand Up @@ -112,6 +116,44 @@ void LangClient::onQuit( int exitCode )
new SCRequestEvent( Event_SCRequest_Quit, exitCode ) );
}

void LangClient::onLibraryShutdown()
{
// NOTE: Finalization does not work properly in sclang:
// finalizers of still accessible objects are not called at shutdown.
// Therefore we finalize here manually.

QtCollider::lockLang();
if(!compiledOK) {
QtCollider::unlockLang();
return;
}

VMGlobals *g = gMainVMGlobals;

// Get the 'heap' classvar of QObject:
int idx = slotRawInt( &SC_CLASS(QObject)->classVarIndex );
PyrSlot *heap_slot = slotRawObject( &g->process->classVars )->slots + idx;

if (IsObj(heap_slot))
{
// Delete all objects on heap:
PyrObject *heap = slotRawObject( heap_slot );
int n = heap->size;
for(int i = 0; i < n; ++i)
{
PyrObject *object = slotRawObject(heap->slots+i);
QObjectProxy *proxy = static_cast<QObjectProxy*>(slotRawPtr(object->slots));
proxy->finalize();
proxy->destroy( QObjectProxy::DestroyObject );
// Destroy the proxy later, to keep it safe for other shutdown handlers:
DestroyEvent *e = new DestroyEvent( QObjectProxy::DestroyProxy );
QApplication::postEvent( proxy, e );
}
}

QtCollider::unlockLang();
}

void LangClient::customEvent( QEvent *e )
{
int type = e->type();
Expand Down
1 change: 1 addition & 0 deletions QtCollider/LanguageClient.h
Expand Up @@ -56,6 +56,7 @@ private Q_SLOTS:
virtual void daemonLoop();

virtual void onQuit( int exitCode );
virtual void onLibraryShutdown();

virtual void customEvent( QEvent * );
virtual void timerEvent( QTimerEvent * );
Expand Down
6 changes: 0 additions & 6 deletions SCClassLibrary/QtCollider/QObject.sc
Expand Up @@ -50,12 +50,6 @@ QObject {

*heap { ^heap.copy }

*initClass {
ShutDown.add {
heap.do { |x| x.prFinalize; };
};
}

initQObject{ arg className, argumentArray;
this.prConstruct( className, argumentArray );
heap = heap.add( this );
Expand Down
4 changes: 0 additions & 4 deletions SCClassLibrary/QtCollider/QWindow.sc
Expand Up @@ -84,10 +84,6 @@ QWindow

*implementsClass {^'Window'}

*initClass {
ShutDown.add( { QWindow.closeAll } );
}

*screenBounds {
_QWindow_ScreenBounds
}
Expand Down

0 comments on commit 9142ba9

Please sign in to comment.