ID3DXBuffer returns null -> crash
Closed this issue · 8 comments
OK, you wouldn't believe thus unless you'd seen it with your own two eyes. This is far from the first report I've got of this:
TASEmulators/BizHawk#623
in String^ Utilities::BufferToString( ID3DXBuffer *buffer )
we have GetBufferPointer() returning NULL. Looking around on the web, I can't find ANYONE who tests it for null before printing it.
Maybe all their error printing routines can handle null pointers? Or maybe they're not trying to get the error string unless the D3DXCompileShader fails? Anyway, slimdx chokes trying to make a managed string out of it. I'm changing the code to this and having my guys test it:
String^ Utilities::BufferToString( ID3DXBuffer *buffer )
{
if( buffer != NULL )
{
LPVOID ptr = buffer->GetBufferPointer();
if(!ptr)
return String::Empty;
String^ string = gcnew String( reinterpret_cast<const char*>( ptr ) );
buffer->Release();
return string;
}
else
{
return String::Empty;
}
}
I'm using the same OS and driver version they are and I don't have this problem. I'm sure it's something wrong with some people's systems, but I think it's a freak misfortune that it chokes slimdx. Maybe the problem's at the D3DX layer? Anyway, easy to workaround.
I'm happy to add the fix, but I admit, I'm surprised that the buffer can be valid without a valid pointer. Why would the compiler return a buffer if there's nothing in it? Just another odd quirk hiding deep in the runtime system, I suppose.
its not the runtime its you not clearing the buffer when I read your own code.
h wait you do use a release. hmm
maybe try setting the buffer variable to null right after clearing?
Wait yeah you should try if you can do a buffer->Clear();
I would love someone else to chime in here, but I can't make any sense of your reply. What's "your own code"?
see if you can do a buffer->Clear();
or ptr = NULL;
or buffer = NULL;
after you are done with it.
Sadly I havent read everything on Pointers I sadly have to wait till next Week to try to get a C++ book. All I know is from Trial and error.
oh wait it was fixed already. Why is this not closed then?
I dont know, was it fixed? I just posted a suggested fix here and said I'd have my guys test it, but we havent made a new release since then.
oh. well then. thanks for noticing. ill write back if i discover theres more trouble.