jintal
27-10-2007 12:45:12
hi guys, i've previously used python-ogre and now i've been playing with mogre for the past month.
The problem is that my app works.. but after 10-20 seconds, access violations occur.
I've closed in on the problematic code. When i take off my input listener, the access violation goes away. but ofcourse, i need the inputs to work.
The code below is the part of my input listener class where the error is.
in a nutshell, the ListenerProcedure method is the one called at the start of every frame. The for each statement below the FInputKeyboard.Capture() is where the problem is. when i comment this out, the problem disappears.
It's weird because the input listener works and i can get the all keypresses...
please help out. i'm kinda stuck with this one.
The problem is that my app works.. but after 10-20 seconds, access violations occur.
I've closed in on the problematic code. When i take off my input listener, the access violation goes away. but ofcourse, i need the inputs to work.
The code below is the part of my input listener class where the error is.
in a nutshell, the ListenerProcedure method is the one called at the start of every frame. The for each statement below the FInputKeyboard.Capture() is where the problem is. when i comment this out, the problem disappears.
Imports MOIS
Namespace Listeners
''' <summary>
''' This performs the necessary logging of all keyboard and mouse events.
''' </summary>
''' <remarks></remarks>
Public Class InputListener
Inherits BaseListener
Private FInputManager As InputManager
Private FInputMouse As Mouse
Private FInputKeyboard As Keyboard
Private FPreviouslyPressedKeys As New List(Of KeyCode)
Private FPreviouslyClickedButtons As New List(Of MouseButtonID)
' Q-P, A-L, Z-M, 1-0, ESC, F1-F12, SPACE
Private FKeyCodesToListenFor = New Integer()() {New Integer() {16, 25}, _
New Integer() {30, 38}, _
New Integer() {44, 50}, _
New Integer() {2, 11}, _
New Integer() {1, 1}, _
New Integer() {59, 88}, _
New Integer() {57, 57}}
Public Sub New()
Dim plParams As New MOIS.ParamList
Dim ptrWindow As System.IntPtr
MOgreWindow.Singleton.RenderWindow.GetCustomAttribute("WINDOW", ptrWindow)
plParams.Insert("WINDOW", ptrWindow.ToString)
FInputManager = InputManager.CreateInputSystem(plParams)
FInputKeyboard = FInputManager.CreateInputObject(Type.OISKeyboard, False)
FInputMouse = FInputManager.CreateInputObject(Type.OISMouse, False)
FInputKeyboard.SetBuffered(True)
plParams.Dispose()
End Sub
Public Overrides Function ListenerProcedure(ByVal anEvent As FrameEvent) As Boolean
CheckKeyboard()
Return True
End Function
Private Sub CheckKeyboard()
Try
' Capture the keyboard presses
FInputKeyboard.Capture()
' only record a key once it is pressed
For Each intKeyCodes As Integer() In FKeyCodesToListenFor
For i As Integer = intKeyCodes(0) To intKeyCodes(1)
If FInputKeyboard.IsKeyDown(i) And Not FPreviouslyPressedKeys.Contains(i) Then
KeyPresses.Singleton.Append(i)
FPreviouslyPressedKeys.Add(i)
ElseIf Not FInputKeyboard.IsKeyDown(i) Then
FPreviouslyPressedKeys.Remove(i)
End If
Next
Next
Catch ex As Exception
End Try
End Sub
Protected Overrides Sub Finalize()
Try
FInputManager.DestroyInputObject(FInputMouse)
FInputManager.DestroyInputObject(FInputKeyboard)
InputManager.DestroyInputSystem(FInputManager)
Finally
MyBase.Finalize()
End Try
End Sub
End Class
End Namespace
It's weird because the input listener works and i can get the all keypresses...
please help out. i'm kinda stuck with this one.