  
Welcome to Ventspace! Most posts here are delayed copies of posts from the real Ventspace.
| Thursday, October 1, 2009 |
 Subtleties of .NET and a SlimDX Crash Bug |
Posted - 10/1/2009 1:49:25 PM | Let's look at a real, in the trenches SlimDX bug that results from a problematic subtlety in .NET. This one isn't even fixed in trunk yet. Here's our main function of interest:
generic<typename T> where T : value class
Result BaseEffect::SetValue( EffectHandle^ parameter, T value )
{
HRESULT hr;
D3DXHANDLE handle = parameter != nullptr ? parameter->InternalHandle : NULL;
if( T::typeid == bool::typeid )
{
BOOL newValue = Convert::ToInt32( value, CultureInfo::InvariantCulture );
hr = InternalPointer->SetBool( handle, newValue );
}
else if( T::typeid == float::typeid )
{
hr = InternalPointer->SetFloat( handle, static_cast<FLOAT>( value ) );
}
else if( T::typeid == int::typeid )
{
hr = InternalPointer->SetInt( handle, static_cast<INT>( value ) );
}
else if( T::typeid == Matrix::typeid )
{
hr = InternalPointer->SetMatrix( handle, reinterpret_cast<D3DXMATRIX*>( &value ) );
}
else if( T::typeid == Vector4::typeid )
{
hr = InternalPointer->SetVector( handle, reinterpret_cast<D3DXVECTOR4*>( &value ) );
}
else
{
hr = InternalPointer->SetValue( handle, &value, static_cast<DWORD>( sizeof(T) ) );
}
return RECORD_D3D9( hr );
}
This function will crash randomly on good input. Specifically, D3D will return a D3DERR_INVALIDCALL, which then gets translated to an exception. Again, that's on known-good input. The call to the function looks like this:
effect.SetValue<float>("alpha", 0.5f);
When this call is made, an EffectHandle is implicitly constructed that copies the string into native memory. Here's the relevant bits of EffectHandle:
EffectHandle::EffectHandle( String^ name )
{
m_StringData = Marshal::StringToHGlobalAnsi( name );
m_HasString = true;
m_StringDataSize = name->Length;
GC::AddMemoryPressure( m_StringDataSize );
m_Handle = reinterpret_cast<D3DXHANDLE>( m_StringData.ToPointer() );
}
void EffectHandle::Destruct()
{
if( m_HasString )
{
Marshal::FreeHGlobal( m_StringData );
GC::RemoveMemoryPressure( m_StringDataSize );
}
}
So. Do you see where we screwed this up?
In case it's not clear:
* EffectHandle::InternalHandle returns EffectHandle::m_Handle
* D3DXHANDLE is a typedef for char*
* Although there's plenty of interop, the interop is NOT the root cause.
HINT: EffectHandle is finalizable. Answer is in comments.
| |
| Tuesday, September 29, 2009 |
 Oh hell yes. |
Posted - 9/29/2009 8:39:15 AM | 
| |
| Thursday, September 24, 2009 |
 Revolution, Part 2: BioReplicant Animation |
Posted - 9/24/2009 11:52:13 PM | I promised this a long time ago, and here it is. I prefer to let the video speak for itself. This is a demo from January, so it’s actually a much older iteration of what we’ve got now.
Link!
| |
| Friday, September 18, 2009 |
 Our iPhone/iPod Touch game is out! |
Posted - 9/18/2009 5:31:06 PM | Link

I'll concede it doesn't look like much, but honestly, the game is really addictive and fun. And it's a dollar.
One of the technologies in this is the binaural audio system that I discussed earlier. On the above page, there's a linked video -- put on headphones and watch it. You'll get the point very quickly. It's even better in-game than in the video, was my experience.
There's also the animation system, which is not really shown off that well here, but it's procedurally constructed, like NaturalMotion (but better, we believe). At no point were any animations build in a modeler. It's all done dynamically using relatively simple rules. The future games will leverage this tech more heavily, but at least as developers I think you can appreciate how awesome that is. The flying, the hits -- it's all physics based.
Did I mention it's a dollar? Try it out. And if you do try it out, please take the time to write an honest (and hopefully positive!) review. It'll go a long way for us if you do.


| |
|
| S | M | T | W | T | F | S | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
OPTIONS
Track this Journal
ARCHIVES
October, 2009
September, 2009
August, 2009
July, 2009
June, 2009
October, 2008
June, 2008
May, 2008
April, 2008
March, 2008
February, 2008
January, 2008
December, 2007
November, 2007
October, 2007
September, 2007
August, 2007
July, 2007
June, 2007
May, 2007
February, 2007
|