What am I doing Wrong : vb.net key movment

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
JonC

What am I doing Wrong : vb.net key movment

Post by JonC »

Hey, I've been working on tutorial 4 for some thime now, reading almost every post in i forum, and thingk I have everything koorekt, but :

I'm using this class for the EventeReceiver :

Code: Select all

Public Class MyEventReceiver
    Implements IEventReceiver

    Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
        If e.Type = EventType.KeyInput Then
            '37=leftkey,38=upkey,39=rightkey,40=downkey, 
            If e.Key = 38 Then
                Console.Write("Du har presset meg")
            End If

        End If

        Return False
    End Function


End Class
But when i do thins :

Code: Select all

device.EventReceiver = New MyEventReceiver()
I get a error the next time i use the device. :
An unhandled exception of type 'System.NullReferenceException' occurred in irrlicht.net.dll

Additional information: Object reference not set to an instance of an object.

If i drop the device.EventReceiver, the rest of the kode works fine...

What could I be doing woring??
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

are you doing this:

device.EventReceiver = New MyEventReceiver()

before you create the device? Because if you are, you can't. Device would not be initialized yet. Can you create the event receiver and pass it to the device when you create (like you're supposed to do in c++)?
JonC

No

Post by JonC »

Of course not(not a complete idiot( or am I?)), I'll paste the koplete code :

Code: Select all

Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.GUI
Imports Irrlicht.IO
Imports Irrlicht.Video
Imports Irrlicht.Scene

Public Class engine

    '' Main Grafiks device
    Private device As IrrlichtDevice

    '' Main Camra
    Private camra As ICameraSceneNode
    Private node As ISceneNode


    Sub New()

        Me.initiate()
        Me.addElements()
        Me.startEngine()

    End Sub

    Private Sub initiate()
        Console.WriteLine(" - Initiate start ")
        '' Setter Hoved grafikk elementet
        device = New IrrlichtDevice(DriverType.DIRECT3D9, New Irrlicht.Core.Dimension2D(800, 600), 16, False, True, True)
        Console.WriteLine(device.Version)
        device.EventReceiver = New MyEventReceiver()
        device.ResizeAble = False
        device.WindowCaption = "MainWin"

        '' Setter hoved camra
        camra = device.SceneManager.AddCameraSceneNodeFPS(Nothing, 100, 100, -1)
        camra.Position = New Vector3D(10, 0, 0)
        device.EventReceiver = New MyEventReceiver()
        ''Fjerner visning av musen på skjermen
        device.CursorControl.Visible = False

        Console.WriteLine(" - Initiate slutt ")
    End Sub


    Private Sub addElements()


        Dim txtWall As ITexture = device.VideoDriver.GetTexture("wall.jpg")
        node = device.SceneManager.AddTestSceneNode(15, Nothing, -1, New Vector3D(100, 100, -10))
        node.SetMaterialTexture(0, txtWall)


        Dim texSydney As ITexture = device.VideoDriver.GetTexture("sydney.bmp")
        Dim mesh As Irrlicht.Scene.IAnimatedMesh = device.SceneManager.GetMesh("sydney.md2")
        node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, Nothing, -1)

        node.SetMaterialTexture(0, texSydney)
        node.SetMaterialFlag(MaterialFlag.LIGHTING, False)


    End Sub

    Private Sub startEngine()
        Console.WriteLine(" - startEngine start ")
        While device.Run = True
            If device.WindowActive Then
                '' Starter ny scene
                device.VideoDriver.BeginScene(True, True, New Color(-1, 100, 100, 100))

                '' Tegner elementer
                device.SceneManager.DrawAll()

                ''avslutter
                device.VideoDriver.EndScene()

            End If
        End While

    End Sub





End Class



Public Class MyEventReceiver
    Implements IEventReceiver

    Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
        If e.Type = EventType.KeyInput Then
            '37=leftkey,38=upkey,39=rightkey,40=downkey, 
            If e.Key = 38 Then
                Console.Write("Du har presset meg")
            End If
        End If

        Return False
    End Function


End Class

pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Code: Select all

Private Sub initiate()
        Console.WriteLine(" - Initiate start ")
        '' Setter Hoved grafikk elementet
        device = New IrrlichtDevice(DriverType.DIRECT3D9, New Irrlicht.Core.Dimension2D(800, 600), 16, False, True, True)
        Console.WriteLine(device.Version)
        device.EventReceiver = New MyEventReceiver()
        device.ResizeAble = False
        device.WindowCaption = "MainWin"

        '' Setter hoved camra
        camra = device.SceneManager.AddCameraSceneNodeFPS(Nothing, 100, 100, -1)
        camra.Position = New Vector3D(10, 0, 0)
        device.EventReceiver = New MyEventReceiver()
        ''Fjerner visning av musen på skjermen
        device.CursorControl.Visible = False

        Console.WriteLine(" - Initiate slutt ")
    End Sub 
Looks like you create the event receiver twice
JonC

Still Dosent work

Post by JonC »

Code: Select all

    Private Sub initiate()
        Console.WriteLine(" - Initiate start ")
        '' Setter Hoved grafikk elementet
        device = New IrrlichtDevice(DriverType.DIRECT3D9, New Irrlicht.Core.Dimension2D(800, 600), 16, False, True, True)
        Console.WriteLine(device.Version)
        device.EventReceiver = New MyEventReceiver()
        device.ResizeAble = False
        device.WindowCaption = "MainWin"

        '' Setter hoved camra
        camra = device.SceneManager.AddCameraSceneNodeFPS(Nothing, 100, 100, -1)
        camra.Position = New Vector3D(10, 0, 0)

        ''Fjerner visning av musen på skjermen
        device.CursorControl.Visible = False

        Console.WriteLine(" - Initiate slutt ")
    End Sub

I've deleted the line, but still get the same error.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

I've never used vb.net with Irrlicht, so I don't know if this is the problem, but maybe you aren't supposed to do 'new IrrlichtDevice(..);' There's a CreateDevice function that is supposed to handle this.
namik
Posts: 11
Joined: Thu Nov 03, 2005 8:12 pm
Contact:

Post by namik »

The GC (Garbage Collector) might be cleaning it up if the MyEventHandler object is stored as a pointer. Try setting a global variable first.

Code: Select all

Public Class Engine
  Public TheEventHandler As MyEventHandler

  Public Sub Initiate
    TheEventHandler = New MyEventHandler;
    . . . initialize device . . .
    device.EventReceiver = TheEventHandler

Silbermünze
Posts: 34
Joined: Thu Sep 15, 2005 12:27 pm
Location: Stuttgart, Germany

Post by Silbermünze »

Did you try running the app in fullscreen mode and see if the event receiver works there?

Just a guess.

I am using Irrlicht.NET from C# and it works fine, the same way you do it.

1. Create IrrlichtDevice
2. Create EventReceiver
3. Assign EventReceiver to IrrlichtDevice
Panther
Posts: 34
Joined: Tue Jun 06, 2006 1:05 am

Same bug with IEventReceiver as JonC

Post by Panther »

I get the error "Object reference not set to an instance of an object" at this line:
While device.Run() = True
But if I comment out this line:
device.EventReceiver = New MyEventReceiver()
Then it works fine! The girl runs by, and the cube spins around!!

I am grasping at straws here, but I am using VB .NET 2002. Everyone seems to be using 2003. Could it be something like that?
Terrachild
Posts: 21
Joined: Sun Sep 03, 2006 5:58 am

VB.NET eventreceiver problem

Post by Terrachild »

I have exactly the same problem. The code crashes in the same spot as you. I have been stuck on this for days. I'm using 2002 also, with VB.NET

My program is structured a little differently, but it is copied from the VB.NET example in the WIKI. You'd think posted code would work!!!

Does anyone have a solution for this yet? :evil:
Braneloc
Posts: 68
Joined: Fri Jan 20, 2006 5:12 am
Location: England
Contact:

Post by Braneloc »

Dammit guys, VS2002 is a nightmare, and well known for being a problem. Even microsoft knew which is why VS2003 came out so quick. Almost nothing posted will work in VS2002, virtually nobody uses it any more !

UPGRADE ALREADY - VS2005 Express is FREE - there is absolutely no excuse for using VS2002 !! You will also move from .net 1.0 to .net 2.0 - that's worth it in its own right (and you need at least 1.1 to keep your sanity). Yes, you can use it side by side with the old version if you really want to.

http://msdn.microsoft.com/vstudio/express/
http://www.irrforge.org/index.php/Irrli ... press_2005
Sometimes you've just gotta say, the laws of time and space, who gives a smeg ?!

Irrlicht.Net Information - http://www.irrforge.org/index.php/.net
Irrlicht# (aka the C# port) - http://irrlichtsharp.sourceforge.net
Terrachild
Posts: 21
Joined: Sun Sep 03, 2006 5:58 am

Solved finaly!!!

Post by Terrachild »

Thank you Braneloc.

I downloaded VB Express, and it converted my old code without fault.
It ran the first time, the OnEvent sub worked, and the nodes moved with the W, and S keys.

Thank you.

Long live VB2005 Express. Maybe Microsoft isn't so bad after all. :D :D :D
Locked