From 219cd6ecda60e1c48852f582f0994573fd0e10ae Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Thu, 14 Oct 2010 21:23:23 -0600
Subject: [PATCH] more debug code for SH-207: viewer crash in
 LLVertexBuffer::mapBuffer.

---
 indra/llcommon/llsys.cpp          | 3 ++-
 indra/llcommon/llsys.h            | 2 +-
 indra/llrender/llvertexbuffer.cpp | 8 +++++++-
 indra/newview/llappviewer.cpp     | 4 ++--
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp
index 7a82a17d0b..10cdc7087b 100644
--- a/indra/llcommon/llsys.cpp
+++ b/indra/llcommon/llsys.cpp
@@ -635,7 +635,8 @@ U32 LLMemoryInfo::getPhysicalMemoryClamped() const
 	}
 }
 
-void LLMemoryInfo::getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb) const
+//static
+void LLMemoryInfo::getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb)
 {
 #if LL_WINDOWS
 	MEMORYSTATUSEX state;
diff --git a/indra/llcommon/llsys.h b/indra/llcommon/llsys.h
index 35425f38ed..41a4f25000 100644
--- a/indra/llcommon/llsys.h
+++ b/indra/llcommon/llsys.h
@@ -116,7 +116,7 @@ public:
 	U32 getPhysicalMemoryClamped() const; ///< Memory size in clamped bytes
 
 	//get the available memory infomation in KiloBytes.
-	void getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb) const;
+	static void getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb);
 };
 
 
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index fd5136e58b..02160b09c4 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -27,7 +27,7 @@
 #include "linden_common.h"
 
 #include <boost/static_assert.hpp>
-
+#include "llsys.h"
 #include "llvertexbuffer.h"
 // #include "llrender.h"
 #include "llglheaders.h"
@@ -856,6 +856,12 @@ U8* LLVertexBuffer::mapBuffer(S32 access)
 		{
 			log_glerror();
 
+			//check the availability of memory
+			U32 avail_phy_mem, avail_vir_mem;
+			LLMemoryInfo::getAvailableMemoryKB(avail_phy_mem, avail_vir_mem) ;
+			llinfos << "Available physical mwmory(KB): " << avail_phy_mem << llendl ; 
+			llinfos << "Available virtual memory(KB): " << avail_vir_mem << llendl;
+
 			//--------------------
 			//print out more debug info before crash
 			llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ;
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index f6cff3d443..3a98749c0f 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1012,7 +1012,7 @@ bool LLAppViewer::mainLoop()
 				memCheckTimer.reset() ;
 
 				//update the availability of memory
-				gSysMemory.getAvailableMemoryKB(mAvailPhysicalMemInKB, mAvailVirtualMemInKB) ;
+				LLMemoryInfo::getAvailableMemoryKB(mAvailPhysicalMemInKB, mAvailVirtualMemInKB) ;
 			}
 			llcallstacks << "Available physical mem(KB): " << mAvailPhysicalMemInKB << llcallstacksendl ;
 			llcallstacks << "Available virtual mem(KB): " << mAvailVirtualMemInKB << llcallstacksendl ;
@@ -1252,7 +1252,7 @@ bool LLAppViewer::mainLoop()
 				llinfos << "Availabe physical memory(KB) at the beginning of the frame: " << mAvailPhysicalMemInKB << llendl ;
 				llinfos << "Availabe virtual memory(KB) at the beginning of the frame: " << mAvailVirtualMemInKB << llendl ;
 
-				gSysMemory.getAvailableMemoryKB(mAvailPhysicalMemInKB, mAvailVirtualMemInKB) ;
+				LLMemoryInfo::getAvailableMemoryKB(mAvailPhysicalMemInKB, mAvailVirtualMemInKB) ;
 
 				llinfos << "Current availabe physical memory(KB): " << mAvailPhysicalMemInKB << llendl ;
 				llinfos << "Current availabe virtual memory(KB): " << mAvailVirtualMemInKB << llendl ;
-- 
GitLab