From 1c3d699120d0acdda3ad0d8a91d113c5d051b56d Mon Sep 17 00:00:00 2001
From: Alexander von Gluck IV <kallisti5@unixzen.com>
Date: Tue, 21 Jan 2014 18:40:22 +0000
Subject: hgl: atomic stores no longer need to be volatile

* Our atomics were revamped to no longer require
  volatile int pointers

diff --git a/include/HaikuGL/GLRenderer.h b/include/HaikuGL/GLRenderer.h
index 7ffcc34..02a438d 100644
--- a/include/HaikuGL/GLRenderer.h
+++ b/include/HaikuGL/GLRenderer.h
@@ -61,7 +61,7 @@ private:
 	virtual status_t		_Reserved_Renderer_3(int32, void *);
 	virtual status_t		_Reserved_Renderer_4(int32, void *);
 
-	volatile int32			fRefCount;	// How much we're still usefull?
+	int32					fRefCount;	// How much we're still usefull?
 	BGLView*				fView;		// Never forget who is the boss!
 	ulong					fOptions;	// Keep that tune in memory
 	BGLDispatcher*			fDispatcher;// Our personal GL API call dispatcher
-- 
1.8.3.4


From fc10a0e496d3c8ea8a027b1807ad9cd7d1c4591d Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Wed, 12 Feb 2014 20:11:25 +0000
Subject: hgl: release add-ons on GLView destruction.


diff --git a/src/hgl/libgl-haiku/GLRendererRoster.cpp b/src/hgl/libgl-haiku/GLRendererRoster.cpp
index 1712a87..3833b2c 100644
--- a/src/hgl/libgl-haiku/GLRendererRoster.cpp
+++ b/src/hgl/libgl-haiku/GLRendererRoster.cpp
@@ -79,7 +79,14 @@ GLRendererRoster::GLRendererRoster(BGLView* view, ulong options)
 
 GLRendererRoster::~GLRendererRoster()
 {
-
+	RendererMap::iterator iterator = fRenderers.begin();
+	for (; iterator != fRenderers.end(); iterator++) {
+		struct renderer_item item = iterator->second;
+		image_id image = item.image;
+		item.renderer->Release();
+		// this will delete the renderer
+		unload_add_on(image);
+	}
 }
 
 
@@ -91,6 +98,7 @@ GLRendererRoster::GetRenderer(int32 id)
 		return NULL;
 
 	struct renderer_item item = iterator->second;
+	item.renderer->Acquire();
 	return item.renderer;
 }
 
@@ -105,7 +113,7 @@ GLRendererRoster::AddDefaultPaths()
 		B_SYSTEM_ADDONS_DIRECTORY,
 	};
 
-	for (uint32 i = fSafeMode ? 4 : 0;
+	for (uint32 i = fSafeMode ? 3 : 0;
 		i < sizeof(paths) / sizeof(paths[0]); i++) {
 		BPath path;
 		status_t status = find_directory(paths[i], &path, true);
diff --git a/src/hgl/libgl-haiku/GLView.cpp b/src/hgl/libgl-haiku/GLView.cpp
index 9ae5b5c..477b430 100644
--- a/src/hgl/libgl-haiku/GLView.cpp
+++ b/src/hgl/libgl-haiku/GLView.cpp
@@ -57,8 +57,11 @@ BGLView::BGLView(BRect rect, const char* name, ulong resizingMode, ulong mode,
 BGLView::~BGLView()
 {
 	delete fClipInfo;
-	if (fRenderer)
+	if (fRenderer) {
 		fRenderer->Release();
+		fRenderer = NULL;
+	}
+	delete fRoster;
 }
 
 
-- 
1.8.3.4

