Browse files

qtcollider: close all windows earlier in class library recompilation

  • Loading branch information...
1 parent 382cecc commit 9142ba9b72b15f95f535d9b581764076f4ccb355 @jleben jleben committed May 4, 2012
View
42 QtCollider/LanguageClient.cpp
@@ -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>
@@ -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();
View
1 QtCollider/LanguageClient.h
@@ -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 * );
View
6 SCClassLibrary/QtCollider/QObject.sc
@@ -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 );
View
4 SCClassLibrary/QtCollider/QWindow.sc
@@ -84,10 +84,6 @@ QWindow
*implementsClass {^'Window'}
- *initClass {
- ShutDown.add( { QWindow.closeAll } );
- }
-
*screenBounds {
_QWindow_ScreenBounds
}

0 comments on commit 9142ba9

Please sign in to comment.