Code: Select all
Thread gameLoopThread;
public MainWindow() {
InitializeComponent();
}
void MainWindow_Load(object sender, EventArgs e) {
DllExport.init(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height);
gameLoopThread = new Thread(new ThreadStart(GameLoop));
gameLoopThread.Start();
}
void GameLoop() {
CycleTimer.TriggerUpdate += CycleTimer_TriggerUpdate;
CycleTimer.TriggerDraw += CycleTimer_TriggerDraw;
CycleTimer.Start(30);
while (true) {
CycleTimer.Update();
}
}
void CycleTimer_TriggerDraw(object sender, TimerEvent e) {
DllExport.draw(e.SecondsElapsed);
}
void CycleTimer_TriggerUpdate(object sender, TimerEvent e) {
DllExport.update(e.SecondsElapsed);
}
void MainWindow_FormClosing(object sender, FormClosingEventArgs e) {
gameLoopThread.Abort();
}
Code: Select all
static class DllExport {
[DllImport("client.dll")]
public static extern void init(IntPtr handle, int width, int height);
[DllImport("client.dll")]
public static extern void update(float secondsElapsed);
[DllImport("client.dll")]
public static extern void draw(float secondsElapsed);
}
On the C++ side of things, this is what happens when init() is called:
Code: Select all
void EngineCore::init(HWND windowHandle, int width, int height)
{
SIrrlichtCreationParameters params;
params.DeviceType = EIDT_BEST;
params.DriverType = EDT_OPENGL;
params.WindowId = windowHandle;
dimension2d<u32> windowSize(width, height);
params.WindowSize = windowSize;
device_ = createDeviceEx(params);
driver_ = device_->getVideoDriver();
sceneManager_ = device_->getSceneManager();
}
Code: Select all
void EngineCore::draw()
{
driver_->beginScene();
sceneManager_->drawAll();
driver_->endScene();
}
Code: Select all
An unhandled exception of type 'System.AccessViolationException' occurred in []
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.