summaryrefslogtreecommitdiffstats
path: root/abs/core/projectm-complete/error-handling.patch
blob: 4154884ab2f3e3c03cfcf24d066ea67670270d9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
Description: Error handling
 * Guard against reinitializing the builtin milkdrop functions.
   Hides a deeper issue where something is double loading the preset factories, most
   likely.
 * Playlist file / directory error handling fixes, resize playlist refresh fix
 
Forwarded: yes
Author: Carmelo Piccione <carmelo.piccione@gmail.com>
Last-Update: 2010-07-29
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp
@@ -29,7 +29,7 @@
   /* Create new function */
   func = new Func(name, func_ptr, num_args);
 
-  if (func == NULL)
+  if (func == 0)
     return PROJECTM_OUTOFMEM_ERROR;
 
   retval = insert_func( func );
@@ -115,12 +115,18 @@
   return PROJECTM_SUCCESS;
 }
 
+volatile bool BuiltinFuncs::initialized = false;
 
 /* Initialize the builtin function database.
    Should only be necessary once */
 int BuiltinFuncs::init_builtin_func_db() {
   int retval;
 
+  if (initialized) {
+    return 0;
+  } else
+    initialized = true;
+  
   retval = load_all_builtin_func();
   return retval;
 }
@@ -134,7 +140,7 @@
 traverse<TraverseFunctors::Delete<Func> >(builtin_func_tree);
 
 builtin_func_tree.clear();
-
+initialized = false;
 return PROJECTM_SUCCESS;
 }
 
@@ -142,13 +148,24 @@
 int BuiltinFuncs::insert_func( Func *func ) {
 
   assert(func);
-  std::pair<std::map<std::string, Func*>::iterator, bool> inserteePair =
-  	builtin_func_tree.insert(std::make_pair(std::string(func->getName()), func));
   
+  if (func == 0) {
+      std::cerr << "Received a null function object, ignoring...." << std::endl;
+      return PROJECTM_ERROR;
+  }
+  
+//   //std::cout << "inserting function " << func->getName() << std::endl;
+  
+  const std::pair<std::string, Func*> pair = std::make_pair(std::string(func->getName()), func);
+  
+  assert(pair.second);
+  
+  const std::pair<std::map<std::string, Func*>::iterator, bool> inserteePair =
+  	builtin_func_tree.insert(pair);
+  	
   if (!inserteePair.second) {
 	std::cerr << "Failed to insert builtin function \"" << func->getName() << "\" into collection! Bailing..." << std::endl;
 	abort();
-
   }
 
   return PROJECTM_SUCCESS;
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp
@@ -229,6 +229,7 @@
     static Func *find_func( const std::string & name );
 private:
      static std::map<std::string, Func*> builtin_func_tree;
+     static volatile bool initialized;
 };
 
 #endif
--- a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp
@@ -26,7 +26,7 @@
 	Eval::init_infix_ops();
 
 	_presetOutputs = createPresetOutputs(gx,gy);
-    _presetOutputs2 = createPresetOutputs(gx, gy);
+	_presetOutputs2 = createPresetOutputs(gx, gy);
 }
 
 MilkdropPresetFactory::~MilkdropPresetFactory() {
@@ -37,13 +37,13 @@
 	BuiltinFuncs::destroy_builtin_func_db();
 	std::cerr << "[~MilkdropPresetFactory] delete preset out puts" << std::endl;
 	delete(_presetOutputs);
-    delete(_presetOutputs2);
+        delete(_presetOutputs2);
 	std::cerr << "[~MilkdropPresetFactory] done" << std::endl;
 
 }
 
 /* Reinitializes the engine variables to a default (conservative and sane) value */
-void resetPresetOutputs(PresetOutputs *presetOutputs)
+void resetPresetOutputs(PresetOutputs * presetOutputs)
 {
 
     presetOutputs->zoom=1.0;
--- a/src/libprojectM/PresetFactoryManager.cpp
+++ b/src/libprojectM/PresetFactoryManager.cpp
@@ -20,7 +20,7 @@
 #endif
 
 #include <sstream>
-PresetFactoryManager::PresetFactoryManager() : _gx(0), _gy(0) {}
+PresetFactoryManager::PresetFactoryManager() : _gx(0), _gy(0), initialized(false) {}
 
 PresetFactoryManager::~PresetFactoryManager() {
 	for (std::vector<PresetFactory *>::iterator pos = _factoryList.begin(); 
@@ -29,11 +29,20 @@
 		delete(*pos);
 	}
 
-
+  initialized = false;
 }
+
 void PresetFactoryManager::initialize(int gx, int gy) {
 	_gx = gx;
 	_gy = gy;
+	
+	if (!initialized) {
+	  initialized = true;
+	} else {
+	  std::cout << "already initialized " << std::endl;
+	  return;
+	}
+	  
 	PresetFactory * factory;
 	
 	#ifndef DISABLE_MILKDROP_PRESETS
--- a/src/libprojectM/PresetFactoryManager.hpp
+++ b/src/libprojectM/PresetFactoryManager.hpp
@@ -21,7 +21,7 @@
 		virtual ~PresetFactoryException() throw() {}
 		const std::string & message() const { return _message; } 
 
-	private:	
+	private:
 		std::string _message;
 };
 
@@ -54,6 +54,6 @@
 		mutable std::map<std::string, PresetFactory *> _factoryMap;
 		mutable std::vector<PresetFactory *> _factoryList;
 		void registerFactory(const std::string & extension, PresetFactory * factory);
-
+		volatile bool initialized;
 };
 #endif
--- a/src/libprojectM/projectM.cpp
+++ b/src/libprojectM/projectM.cpp
@@ -222,7 +222,6 @@
     projectM_init ( _settings.meshX, _settings.meshY, _settings.fps,
                     _settings.textureSize, _settings.windowWidth,_settings.windowHeight);
 
-
                     _settings.beatSensitivity = beatDetect->beat_sensitivity = config.read<float> ( "Hard Cut Sensitivity", 10.0 );
 
                     if ( config.read ( "Aspect Correction", true ) )
--- a/src/projectM-pulseaudio/QPulseAudioThread.cpp
+++ b/src/projectM-pulseaudio/QPulseAudioThread.cpp
@@ -296,9 +296,7 @@
 {
 	assert ( mainloop_api );
 	mainloop_api->quit ( mainloop_api, ret );
-	if (*s_qprojectM_MainWindowPtr)
-		delete(*s_qprojectM_MainWindowPtr);
-	*s_qprojectM_MainWindowPtr = 0;
+	
 }
 
 
@@ -315,7 +313,8 @@
 	{
 		fprintf ( stderr, "pa_stream_peek() failed: %s\n", pa_strerror ( pa_context_errno ( context ) ) );
 		pulseQuit ( 1 );
-		return;
+		return
+;
 	}
 
 	if ((!s_qprojectM_MainWindowPtr) || (!*s_qprojectM_MainWindowPtr))
@@ -352,16 +351,16 @@
 	switch ( pa_stream_get_state ( s ) )
 	{
 		case PA_STREAM_UNCONNECTED:
-//			qDebug() << "UNCONNECTED";
+			qDebug() << "UNCONNECTED";
 			break;
 		case PA_STREAM_CREATING:
-//			qDebug() << "CREATED";
+		  qDebug() << "CREATED";
 			break;
 		case PA_STREAM_TERMINATED:
-//			qDebug() << "TERMINATED";
+			qDebug() << "TERMINATED";
 			break;
 		case PA_STREAM_READY:
-//			qDebug() << "READY";
+			qDebug() << "READY";
 			if ( verbose )
 			{
 				const pa_buffer_attr *a;
--- a/src/projectM-qt/qplaylisttableview.hpp
+++ b/src/projectM-qt/qplaylisttableview.hpp
@@ -93,14 +93,14 @@
 	 }
 	 
 	 inline void resizeEvent(QResizeEvent * event) {
-
+		QTableView::resizeEvent(event);
 		emit(resized(event));
 	 }	
 	 
 	 inline void mousePressEvent(QMouseEvent * event) {
 		QAbstractItemView::mousePressEvent(event);
 		if (event->button() == Qt::RightButton) {
-			emit(mousePressed(event, selectedIndexes()));			
+			emit(mousePressed(event, selectedIndexes()));
 		}
 		else
 				;
--- a/src/projectM-qt/qprojectm_mainwindow.cpp
+++ b/src/projectM-qt/qprojectm_mainwindow.cpp
@@ -98,7 +98,8 @@
 
 	connect(ui->tableView, SIGNAL(resized(QResizeEvent *)), this, SLOT(refreshHeaders(QResizeEvent*)));
 	
-	connect(ui->tableView, SIGNAL(mousePressed(QMouseEvent*, const QModelIndexList &)), this, SLOT(popupPlaylistContextMenu(QMouseEvent*, const QModelIndexList &)));
+	connect(ui->tableView, SIGNAL(mousePressed(QMouseEvent*, const QModelIndexList &)), this,
+		SLOT(popupPlaylistContextMenu(QMouseEvent*, const QModelIndexList &)));
 	
 	connect ( m_QProjectMWidget, SIGNAL ( projectM_Initialized(QProjectM*) ), 
 		  this, SLOT ( postProjectM_Initialize() ) );
@@ -662,7 +663,7 @@
 		// Add 1 to skip the Name column
 		hHeader->setResizeMode (i+1, QHeaderView::ResizeToContents);
 		sizeTotal += hHeader->sectionSize(i+1);
-	}				
+	}
 	hHeader->resizeSection(0, ui->tableView->size().width()-20-sizeTotal);
 	
 	
@@ -883,11 +884,13 @@
 		QString url = m_QPlaylistFileDialog->selectedFiles() [0];
 
 		
-		if ( !playlistModel->readPlaylist ( url ) ) { 
+		const bool loadedOk = playlistModel->readPlaylist ( url );
+		
+		if (!loadedOk) { 
 			qDebug() << "could not open playlist";
 			url = QString();
-			
-		}
+		} 
+		
 		qDebug() << "url: " << url;
 		updatePlaylistUrl(url);
 		
--- a/src/projectM-qt/qprojectmwidget.hpp
+++ b/src/projectM-qt/qprojectmwidget.hpp
@@ -22,6 +22,7 @@
 #ifndef QPROJECTM_WIDGET_HPP
 #define QPROJECTM_WIDGET_HPP
 
+#include <iostream>
 #include "qprojectm.hpp"
 #include <QGLWidget>
 #include <QMutex>
@@ -111,7 +112,7 @@
 
 		void resetProjectM()
 		{
-
+			std::cout << "reseting" << std::endl;
 			qDebug() << "reset start";
 
 			emit ( projectM_BeforeDestroy() );
@@ -246,8 +247,10 @@
 		void initializeGL()
 		{
 
-			this->m_projectM = new QProjectM ( m_config_file );
-			projectM_Initialized ( m_projectM );
+		        if (m_projectM == 0) {
+			    this->m_projectM = new QProjectM ( m_config_file );
+			    projectM_Initialized ( m_projectM );
+			}
 		}
 
 		inline void paintGL()