dumpbyte
19-09-2011 14:09:13
Hi guys.
I've implemented in my Mogre application a "mouse-over" functionality, in order to detect what objects are under the mouse pointer. This functionality is executed multiple times per frame, always in the FrameRenderingQueued event.
However, when running the application and observe the Windows TaskManager, I can see how the application is growing in use of memory, until finally I get an OutOfMemoryException.
I'm sure the problem is in this function, as I have not encountered such problems in other applications without this feature .
The code I use is is the following:
Can you tell me guys what is wrong here?
Thanks in advance.
I've implemented in my Mogre application a "mouse-over" functionality, in order to detect what objects are under the mouse pointer. This functionality is executed multiple times per frame, always in the FrameRenderingQueued event.
However, when running the application and observe the Windows TaskManager, I can see how the application is growing in use of memory, until finally I get an OutOfMemoryException.
I'm sure the problem is in this function, as I have not encountered such problems in other applications without this feature .
The code I use is is the following:
Point position;
Point relativeToForm;
Ray mouseRay;
RaySceneQueryResult rayResult;
List<string> pickedObjects;
System.Collections.Generic.IEnumerator<RaySceneQueryResultEntry> itr;
public List<string> GetObjectsUnderCursor()
{
using (RaySceneQuery myRaySceneQuery = myM3DEngine.MogreSceneManager.CreateRayQuery(new Ray()))
{
position = System.Windows.Forms.Cursor.Position;
relativeToForm = myM3DEngine.RenderManager.TargetRenderWindow.PointToClient(position);
float X = (float)relativeToForm.X / (float)myM3DEngine.MogreViewport.ActualWidth;
float Y = (float)relativeToForm.Y / (float)myM3DEngine.MogreViewport.ActualHeight;
mouseRay = myM3DEngine.SceneManager.MogreCamera.GetCameraToViewportRay(X, Y);
myRaySceneQuery.Ray = mouseRay;
myRaySceneQuery.SetSortByDistance(true);
rayResult = myRaySceneQuery.Execute();
itr = rayResult.GetEnumerator();
pickedObjects = new List<string>();
while (itr != null && itr.MoveNext())
{
if (itr.Current.movable != null)
{
pickedObjects.Add(itr.Current.movable.Name);
}
}
myRaySceneQuery.ClearResults();
myRaySceneQuery.Dispose();
rayResult.Dispose();
itr.Dispose();
return pickedObjects;
}
}
Can you tell me guys what is wrong here?
Thanks in advance.