[solved] Weird crash!

Eldritch

31-03-2007 10:36:31

Implemented MogreNewt. This caused quite a weird error to occur in my physics server class: it cannot instantiate its own singleton instance.. I get a TypeInitializationException thrown when I attempt to do so. Here's the code for my physics server:


using System;
using System.Drawing;
using Mogre;
using GFW.Kernel;
using GFW.Canvas;
using GFW.Script;
using GFW.Camera;
using GFW.Project;
using GFW.Game;

namespace GFW.Physics
{
/// <summary>
/// Server managing physics.
/// This server is a non-core server.
/// </summary>
public sealed class CPhysicsServer_s : IPhysicsServer
{
private Vector3 m_vec3Gravity = new Vector3(0.0f, -0.3f, 0.0f);

private MogreNewt.World m_refPhysWorld = null;

/// <summary>Initializes server.</summary>
public void Initialize()
{
CScriptServer_s.Instance.RegisterObj("Physics", Instance);
}

public void SetupPhysWorld()
{
m_refPhysWorld = new MogreNewt.World();
MogreNewt.CollisionPrimitives.TreeCollisionSceneParser parser = new MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(m_refPhysWorld);
parser.parseScene(CObjectLibrary_s.Instance.GetWorldNode(), true);
MogreNewt.Body body = new MogreNewt.Body(m_refPhysWorld, parser);
parser.Dispose();

body.attachToNode(CObjectLibrary_s.Instance.GetWorldNode());
body.setPositionOrientation(CObjectLibrary_s.Instance.GetWorldNode().Position,
CObjectLibrary_s.Instance.GetWorldNode().Orientation);
}

/// <summary>Starts server.</summary>
public void Start()
{
CPickClient_s.Instance.Initialize();
}

public void Update()
{
if (m_refPhysWorld != null)
m_refPhysWorld.update(0.01f); // TODO: should be a scheduled task!
}

public void DestroyPhysWorld()
{
if (m_refPhysWorld != null)
m_refPhysWorld.Dispose();
m_refPhysWorld = null;
}

public MogreNewt.World GetPhysWorld()
{
return m_refPhysWorld;
}

/// <summary>Runs picking by mouse position.</summary>
public void PickByMousePos()
{
Point mp = CCanvas_s.Instance.GetCursorPos();
float screenX = (float)mp.X / CCanvas_s.Instance.Width;
float screenY = (float)mp.Y / CCanvas_s.Instance.Height;

Ray ray = CCamera_s.Instance.GetInternalRef().GetCameraToViewportRay(screenX, screenY);
RaySceneQuery query = CKernel_s.Instance.GetScene().CreateRayQuery(ray);
query.SetSortByDistance(true);
query.QueryTypeMask = SceneManager.ENTITY_TYPE_MASK;
RaySceneQueryResult result = query.Execute();

CPickClient_s.Instance.HandlePick(result);
}

/// <summary>Runs picking by an arbitrary point.</summary>
public void PickByArbitraryPoint(Vector2 vec2ScreenPos)
{
float screenX = vec2ScreenPos.x / CCanvas_s.Instance.Width;
float screenY = vec2ScreenPos.y / CCanvas_s.Instance.Height;

Ray ray = CCamera_s.Instance.GetInternalRef().GetCameraToViewportRay(screenX, screenY);
RaySceneQuery query = CKernel_s.Instance.GetScene().CreateRayQuery(ray);
RaySceneQueryResult result = query.Execute();

CPickClient_s.Instance.HandlePick(result);
}

public void SetGravity(float fX, float fY, float fZ)
{
m_vec3Gravity.x = fX;
m_vec3Gravity.y = fY;
m_vec3Gravity.z = fZ;
}

public Vector3 GetGravity()
{
return m_vec3Gravity;
}

/// <summary>Constructor. Not externally accessible.</summary>
private CPhysicsServer_s()
{
}

/// <summary>Gets singleton instance.</summary>
public static CPhysicsServer_s Instance { get { return m_refInstance; } }

/// <summary>Singleton instance.</summary>
private static CPhysicsServer_s m_refInstance = new CPhysicsServer_s();
}
}



It worked just fine before I started to add MogreNewt stuff. Any ideas what can be wrong?

This is the order in which I am doing stuff:

Application start: I run Initialize() on the physics server by using CPhysServer_s.Instance.Initialize(). This causes the crash.

Before entering main loop: I run SetupPhysWorld() from script, after having loaded all necessary geometry.

Eldritch

31-03-2007 11:14:33

After further studies: Any class that I put something from MogreNewt in will automatically become an invalid class that causes a system crash. Something must really be wrong with MogreNewt...

Blackbeard

31-03-2007 18:28:26

You are "using MogreNewt;" somewhere?