Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 14.01.2006, 00:35   #1
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Question D3DXMesh problem

You guys,

The provided C3DText class definition is supposed to wrap the D3DX text manipulation routines up. It has a simple capability of loading the font, generating the 3D mesh of the text by calling D3DXCreateText and Render()ing the mesh at the given coordinates. A weird problem, however, occurs when instantiating/destructing an instance of the class several (actually a lot of) times: the application crashes with an error message 'The memory could not be "read"'. The call stack reads the line mesh->DrawSubset(0), however my mesh pointer is not null at the moment and when I check with mesh->GetNumVertices() before trying to DrawSubset(0), it is filled with vertices as it should. What in your opinion would cause the crash? Thank you.

PHP Code:
#include ".\3dtext.h"
 
C3DText::C3DText()
{
}
 
C3DText::~C3DText(void)
{
    
delete mesh;
}
 
bool C3DText::Create(LPCSTR text)
{
    
HDC dc;
    
HFONT font;
 
    
dc CreateCompatibleDC(NULL);
    
font CreateFont(10000FW_NORMALfalsefalsefalseDEFAULT_CHARSETOUT_DEFAULT_PRECISCLIP_DEFAULT_PRECISDEFAULT_QUALITYDEFAULT_PITCH FF_DONTCARE"Arial");
    
SelectObject(dcfont);
 
    
HRESULT hr D3DXCreateText(CDirect3D::Instance()->GetDevice(), dctext0.001f0.4f, &meshNULLNULL);
 
    
DeleteObject(font);
    
DeleteDC(dc);
 
    if (
hr == D3DERR_INVALIDCALL)
    {
        
MessageBox(CGameWnd::Instance()->GetHwnd(), "D3DERR_INVALIDCALL""C3DText::Create"0);
        return 
false;
    }
 
    if (
hr == D3DXERR_INVALIDDATA)
    {
        
MessageBox(CGameWnd::Instance()->GetHwnd(), "D3DXERR_INVALIDDATA""C3DText::Create"0);
        return 
false;
    }
 
    if (
hr == E_OUTOFMEMORY)
    {
        
MessageBox(CGameWnd::Instance()->GetHwnd(), "E_OUTOFMEMORY""C3DText::Create"0);
        return 
false;
    }
 
    return 
true;
}
 
void C3DText::Render(int xint y)
{
    
D3DXMATRIX matWorld;
    
D3DXMatrixTranslation(&matWorld, (float)x, (float)-y0);
    
CDirect3D::Instance()->GetDevice()->SetTransformD3DTS_WORLD, &matWorld );
 
    
mesh->DrawSubset(0);
 
//////////////////////
 
 


Last edited by Silver; 14.01.2006 at 13:56.
Reply With Quote
Old 14.01.2006, 13:59   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default SOLVED: D3DXMesh problem

OK, the problem is solved.
In the destructor, should have called mesh->Release() instead of delete'ing it. Cheers.
Reply With Quote
Old 15.01.2006, 17:43   #3
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Lightbulb Re: D3DXMesh problem

2 AvDav:

I've seen that you've deleted your message, but well let me still type this, hopefully it'll ever be of some help for anyone else.
D3DXCreateText() fails with D3DERR_INVALIDCALL, which means that something is wrong with one of the function arguments (presumably the mesh pointer, coz anything else doesn't change during the lifetime of the application). After digging up the documentation, I caught it - you should Release() the mesh instead of delete'ing it, so that Direct3D treats and deletes the pointer the way it should.
The issue of Font and DC is not really an issue when you come to understand how does D3DXCreateText() work, and that is - it takes all the necessary information about the text (for which it needs the device context and the handle of the font used for the text) and generates a 3D mesh (array of vertices) based on that information. After the mesh is generated, it doesn't need the DC or the HFONT anymore, you simply treat the result as a mesh and it doesn't have any text-specific properties. That is why there is absolutely no need to keep the memory busy even for an extra tick after the mesh is successfully generated.
By the way, you may see project involving this topic here in this thread. I can't believe why is everyone so passive there!
Reply With Quote
Old 16.01.2006, 00:10   #4
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: D3DXMesh problem

Well, thanks for informative digression on Direct3D, sincerely don't have any solid DirectX experience, so that were just wild guesses. By the way, your game crashes, saying "Error! CDirect3D::Init() and CreateDevice() failed", my DX version is 9c, HW accelerated v-card (32Mb). What does go wrong?
Reply With Quote
Old 16.01.2006, 00:50   #5
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: D3DXMesh problem

I made some optimizations in the initialization routine, so now the requirements for hardware resources of Video card must be less biting. Try downloading the archive again, it's updated.
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 19:39.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.