SetBlitz3DEventCallback and SetBlitz3DHWND Bug

Blitz3D SDK Forums/Blitz3D SDK Bug Reports/SetBlitz3DEventCallback and SetBlitz3DHWND Bug

Yeah sure, the code below shows the bug in action.


Edit: Obviously this code will not run on it's own, it's just an example.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


using bb = Blitz3DSDK;


namespace TestApp
{
    public partial class Form1 : Form
    {

        // Windows messages
        const int WM_LBUTTONDOWN = 0x201;
        const int WM_LBUTTONUP = 0x202;
        const int WM_LBUTTONDBLCLK = 0x203;
        const int WM_RBUTTONDOWN = 0x204;
        const int WM_RBUTTONUP = 0x205;
        const int WM_RBUTTONDBLCLK = 0x206;
        const int WM_MBUTTONDOWN = 0x207;
        const int WM_MBUTTONUP = 0x208;
        const int WM_MBUTTONDBLCLK = 0x209;
        const int WM_KEYUP = 0x101;

        // The callback function pointer
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate int dBBEventHandler(int hWnd, int Msg, int wParam, int lParam);
        private dBBEventHandler BBEventHandler;

        // this is true when the application should exit
        private bool m_b_exitapp = false;

        // holds info about the last event
        private string m_s_lastevent = "None";

        public Form1()
        {
            InitializeComponent();
        }


        private void btnInitB3D_Click(object sender, EventArgs e)
        {
            // initialise b3d
            bb.SetBlitz3DHWND(RenderPanel.Handle.ToInt32());

            // assign the event handler
            BBEventHandler = new dBBEventHandler(Engine_BBEventHandler);
            bb.SetBlitz3DEventCallback(Marshal.GetFunctionPointerForDelegate(BBEventHandler).ToInt32());

            // setup graphics
            bb.BeginBlitz3D();
            bb.Graphics3D(RenderPanel.Width, RenderPanel.Height, 32);

            // begin the main loop
            MainLoop();
        }


        // the main loop
        private void MainLoop()
        {
            while (!m_b_exitapp)
            {
                Application.DoEvents();

                bb.Cls();
                bb.RenderWorld();
                bb.Text(10, 10, "Last event to occurr: " + m_s_lastevent);
                bb.Flip();
            }

            Application.Exit();
        }


        //The event handler for the callback event
        public int Engine_BBEventHandler(int hWnd, int Msg, int wParam, int lParam)
        {
            // process the event
            switch (Msg)
            {
                case WM_LBUTTONDOWN:
                    // left mouse button is down
                    m_s_lastevent = "Left mouse button down";
                    RenderPanel.Focus();
                    break;

                case WM_RBUTTONDOWN:
                    // right mouse button is down
                    m_s_lastevent = "Right mouse button down";
                    RenderPanel.Focus();
                    break;

                case WM_KEYUP:
                    // keyboard
                    m_s_lastevent = "Keyboard key released";
                    RenderPanel.Focus();
                    break;
            }

            return -1;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            m_b_exitapp = true;
        }
    }
}



Any suggestions on this would be great, because currently I'm not able to use the sdk for what I want to do with it. So, it's kind of a money pit at the moment.