Index: Recast/Source/RecastMesh.cpp
===================================================================
--- Recast/Source/RecastMesh.cpp	(revision 58)
+++ Recast/Source/RecastMesh.cpp	(working copy)
@@ -670,6 +670,7 @@
 		thole[i] = i;
 	}
 
+    {
 	// Triangulate the hole.
 	int ntris = triangulate(nhole, &tverts[0], &thole[0], tris);
 
@@ -688,7 +689,8 @@
 			rcGetLog()->log(RC_LOG_WARNING, "removeVertex: Out of memory 'pregs' (%d).", ntris);
 		goto failure;
 	}
-	
+
+    {
 	unsigned short* tmpPoly = &polys[ntris*nvp];
 			
 	// Build initial polygons.
@@ -753,7 +755,8 @@
 			}
 		}
 	}
-	
+    } // scope guard for tmpPoly
+    } // scope guard for nTris
 	// Store polygons.
 	for (int i = 0; i < npolys; ++i)
 	{
@@ -902,6 +905,7 @@
 			rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'polys' (%d).", maxVertsPerCont*nvp);
 		goto failure;
 	}
+    {
 	unsigned short* tmpPoly = &polys[maxVertsPerCont*nvp];
 
 	for (int i = 0; i < cset.nconts; ++i)
@@ -1050,18 +1054,21 @@
 		return false;
 	}
 	
-	rcTimeVal endTime = rcGetPerformanceTimer();
+    {	
+    rcTimeVal endTime = rcGetPerformanceTimer();
 	
 //	if (rcGetLog())
 //		rcGetLog()->log(RC_LOG_PROGRESS, "Build polymesh: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
 	if (rcGetBuildTimes())
 		rcGetBuildTimes()->buildPolymesh += rcGetDeltaTimeUsec(startTime, endTime);
 	
+    } // scope guard for rcTimeVal
+    } // scope guard for tmpPoly
 	return true;
 
 failure:
 	delete [] vflags;
-	delete [] tmpPoly;
+	//delete [] tmpPoly;
 	delete [] firstVert;
 	delete [] nextVert;
 	delete [] indices;
@@ -1196,11 +1203,12 @@
 	delete [] nextVert;
 	delete [] vremap;
 	
-	rcTimeVal endTime = rcGetPerformanceTimer();
+    {	
+    rcTimeVal endTime = rcGetPerformanceTimer();
 	
 	if (rcGetBuildTimes())
 		rcGetBuildTimes()->mergePolyMesh += rcGetDeltaTimeUsec(startTime, endTime);
-	
+	} // rcTimeVal scope guard
 	return true;
 	
 failure:
Index: Recast/Source/RecastMeshDetail.cpp
===================================================================
--- Recast/Source/RecastMeshDetail.cpp	(revision 58)
+++ Recast/Source/RecastMeshDetail.cpp	(working copy)
@@ -118,7 +118,7 @@
 		idx[i] = i;
 #ifdef WIN32
 	qsort_s(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
-#else
+#elif defined(__APPLE_CC__)
 	qsort_r(&idx[0], idx.size(), sizeof(int), verts, ptcmp);
 #endif
 
@@ -674,8 +674,12 @@
 						   rcPolyMeshDetail& dmesh)
 {
 	rcTimeVal startTime = rcGetPerformanceTimer();
+    rcTimeVal endTime;	
 	
-	if (mesh.nverts == 0 || mesh.npolys == 0)
+	int vcap;
+	int tcap;
+
+    if (mesh.nverts == 0 || mesh.npolys == 0)
 		return true;
 	
 	const int nvp = mesh.nvp;
@@ -760,8 +764,8 @@
 		goto failure;
 	}
 
-	int vcap = nPolyVerts+nPolyVerts/2;
-	int tcap = vcap*2;
+	vcap = nPolyVerts+nPolyVerts/2;
+	tcap = vcap*2;
 
 	dmesh.nverts = 0;
 	dmesh.verts = new float[vcap*3];
@@ -882,7 +886,7 @@
 	delete [] bounds;
 	delete [] poly;
 	
-	rcTimeVal endTime = rcGetPerformanceTimer();
+	endTime = rcGetPerformanceTimer();
 	
 	if (rcGetBuildTimes())
 		rcGetBuildTimes()->buildDetailMesh += rcGetDeltaTimeUsec(startTime, endTime);
Index: Recast/Source/RecastRegion.cpp
===================================================================
--- Recast/Source/RecastRegion.cpp	(revision 58)
+++ Recast/Source/RecastRegion.cpp	(working copy)
@@ -960,6 +960,9 @@
 							int minRegionSize, int mergeRegionSize)
 {
 	rcTimeVal startTime = rcGetPerformanceTimer();
+    rcTimeVal filterStartTime;
+	rcTimeVal filterEndTime;
+    rcTimeVal endTime;
 	
 	unsigned short* src = 0;
 	rcSweepSpan* sweeps = 0;
@@ -1086,14 +1089,14 @@
 	}
 				
 
-	rcTimeVal filterStartTime = rcGetPerformanceTimer();
+	filterStartTime = rcGetPerformanceTimer();
 
-	// Filter out small regions.
+    // Filter out small regions.
 	chf.maxRegions = id;
 	if (!filterSmallRegions(minRegionSize, mergeRegionSize, chf.maxRegions, chf, src))
 		goto failure;
 
-	rcTimeVal filterEndTime = rcGetPerformanceTimer();
+	filterEndTime = rcGetPerformanceTimer();
 	
 	
 	// Write the result out.
@@ -1103,7 +1106,7 @@
 	delete [] src;
 	delete [] sweeps;
 	
-	rcTimeVal endTime = rcGetPerformanceTimer();
+	endTime = rcGetPerformanceTimer();
 
 	if (rcGetBuildTimes())
 	{
Index: Recast/Source/RecastDebugDraw.cpp
===================================================================
--- Recast/Source/RecastDebugDraw.cpp	(revision 58)
+++ Recast/Source/RecastDebugDraw.cpp	(working copy)
@@ -20,7 +20,7 @@
 #include <math.h>
 #include "RecastDebugDraw.h"
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "MeshLoaderObj.h"
 #include "Recast.h"
 
Index: Detour/Source/DetourDebugDraw.cpp
===================================================================
--- Detour/Source/DetourDebugDraw.cpp	(revision 58)
+++ Detour/Source/DetourDebugDraw.cpp	(working copy)
@@ -19,7 +19,7 @@
 #include "DetourDebugDraw.h"
 #include "DetourStatNavMesh.h"
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 
 void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtStatPolyRef ref, const float* col)
 {
Index: RecastDemo/Source/Sample_StatMeshSimple.cpp
===================================================================
--- RecastDemo/Source/Sample_StatMeshSimple.cpp	(revision 58)
+++ RecastDemo/Source/Sample_StatMeshSimple.cpp	(working copy)
@@ -3,7 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "imgui.h"
 #include "Sample.h"
 #include "Sample_StatMeshSimple.h"
Index: RecastDemo/Source/main.cpp
===================================================================
--- RecastDemo/Source/main.cpp	(revision 58)
+++ RecastDemo/Source/main.cpp	(working copy)
@@ -8,7 +8,7 @@
 #endif
 
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "imgui.h"
 #include "imguiRenderGL.h"
 #include "Recast.h"
@@ -544,7 +544,7 @@
 					{
 						showSample = false;
 						showLevels = true;
-						scanDirectory("meshes", ".obj", meshFiles);
+						scanDirectory("Meshes", ".obj", meshFiles);
 					}
 				}
 				if (mesh)
@@ -649,7 +649,7 @@
 				mesh = 0;
 				
 				char path[256];
-				strcpy(path, "meshes/");
+				strcpy(path, "Meshes/");
 				strcat(path, meshName);
 				
 				mesh = new rcMeshLoaderObj;
Index: RecastDemo/Source/Sample_StatMesh.cpp
===================================================================
--- RecastDemo/Source/Sample_StatMesh.cpp	(revision 58)
+++ RecastDemo/Source/Sample_StatMesh.cpp	(working copy)
@@ -3,7 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "imgui.h"
 #include "Sample.h"
 #include "Sample_StatMesh.h"
Index: RecastDemo/Source/Sample_StatMeshTiled.cpp
===================================================================
--- RecastDemo/Source/Sample_StatMeshTiled.cpp	(revision 58)
+++ RecastDemo/Source/Sample_StatMeshTiled.cpp	(working copy)
@@ -3,7 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "imgui.h"
 #include "Sample.h"
 #include "Sample_StatMeshTiled.h"
Index: RecastDemo/Source/Sample_TileMesh.cpp
===================================================================
--- RecastDemo/Source/Sample_TileMesh.cpp	(revision 58)
+++ RecastDemo/Source/Sample_TileMesh.cpp	(working copy)
@@ -21,7 +21,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "SDL.h"
-#include "SDL_Opengl.h"
+#include "SDL_opengl.h"
 #include "imgui.h"
 #include "Sample.h"
 #include "Sample_TileMesh.h"
Index: RecastDemo/Source/imguiRenderGL.cpp
===================================================================
--- RecastDemo/Source/imguiRenderGL.cpp	(revision 58)
+++ RecastDemo/Source/imguiRenderGL.cpp	(working copy)
@@ -226,11 +226,12 @@
 	unsigned char* ttfBuffer = 0;
 	unsigned char* bmap = 0;
 	bool res = false;
-	
+    int size;
+
 	fp = fopen(fontpath, "rb");
 	if (!fp) goto error;
 	fseek(fp, 0, SEEK_END);
-	int size = ftell(fp);
+	size = ftell(fp);
 	fseek(fp, 0, SEEK_SET);
 	
 	ttfBuffer = (unsigned char*)malloc(size); 
@@ -427,3 +428,4 @@
 	}
 	glDisable(GL_SCISSOR_TEST);
 }
+
