I'm writing this demo DirectX app using VC++ .NET 2005. And my appliction
is crashing without any error messages. I managed to figure out the line where
it's failing using MessageBox::Show(); commands. Prints only "Mark 1" & Line is marked red.
Code -
bool
StingRay3DGraphics::CreateVertexBuffer(Device^ device){
try {
vertices = gcnew VertexBuffer(
CustomVertex::PositionColored::typeid, // What type of vertices
3, // How many
device, // The device
Usage::None, // Default usage
CustomVertex::PositionColored::Format, // Vertex format
Pool::Managed); // Default pooling
if (!vertices) { // buffer creation failed
MessageBox::Show ("buffer creation failed");
return false;
}
array<CustomVertex::PositionColored ^> ^verts =
static_cast<array<CustomVertex::PositionColored ^> ^> (vertices->Lock(0,
Direct3D::LockFlags::None));
MessageBox::Show("Mark 1");
verts[0] = gcnew CustomVertex::PositionColored( 0.0F, 1.0F, 0.0F, 0x00ff0000) ;
MessageBox::Show("Mark 2");
verts[1] = gcnew CustomVertex::PositionColored(-0.5F, 0.0F, 0.0F, 0x0000ff00);
verts[2] = gcnew CustomVertex::PositionColored( 0.5F, 0.0F, 0.0F, 0x000000ff);
MessageBox::Show("Mark 3");
vertices->Unlock();
MessageBox::Show("Mark 4");
} catch (Exception^ e) {
MessageBox::Show (String::Format ("Failed:\n\t {0}", e->Message));
Console::Write (String::Format ("Failed:\n\t {0}", e));
return false;
}
return true; // success device->VertexFormat = CustomVertex::PositionColored::Format;
}
Regards,
Amitoj.

Managed C++ (2005) and DirectX - Application Crashes
ckaz
Without any further information, my first guess would be that verts is null, meaning that the Lock(...) call did not succeed. Before proceeding, it would be useful to see if that's correct. If you can't run in Debug mode, then add code between the "Mark 1" messagebox call and the break line, as follows:
if (verts == null)
{
MessageBox::Show("verts is null!");
// abort abort abort - do whatever you need to do to exit gracefully
}
(filling in some kind of graceful abort code in place of that comment, if you like)