2013-04-28 1 views
1

내가 작업하고있는 게임에 스프라이트 클래스를 추가 한 후 사용자가 윈도우 크기를 변경하면 충돌이 발생합니다. 백 버퍼로 렌더링 할 때 비슷한 문제가 발생했습니다. 이것은 OnLostDevice()OnResetDevice() 메서드를 사용하여 해결되었지만 작동하지 않는 것처럼 보입니다.이 시점에서 무엇을해야할지 확신이 서지 않습니다. 누락 된 것 같은 느낌입니다. 끔찍한 명백한 무언가.Game Crashing on Window Resize (Directx9)

Sprite.h :

#pragma once 
#include <d3d9.h> 
#include <d3dx9tex.h> 
#include <string> 

class Sprite 
{ 
public: 
Sprite(void); 
virtual ~Sprite(void); 

bool loadSprite(LPDIRECT3DDEVICE9 device, std::string filename); 

void render(LPDIRECT3DDEVICE9 pDevice, int alpha); 
void setPosition(int x, int y); 
void setSize(int newWidth, int newHeight); 
void OnLostDevice(); 
void OnResetDevice(); 

int getHeight(); 
int getWidth(); 

    private: 
LPD3DXSPRITE sprite; 
LPDIRECT3DTEXTURE9 texture; 
D3DXVECTOR3 position; 
D3DXVECTOR3 scale; 

float width; 
float height; 

}; 

Sprite.cpp 다음 Game.cpp 장치의 손실을 내

#include "sprite.h" 
    #include "D3DManager.h" 

    Sprite::Sprite(void) 
    { 

    } 

Sprite::~Sprite(void) 
{ 
    if (sprite != nullptr) 
     delete sprite; 

    sprite = nullptr; 
} 

    bool Sprite::loadSprite(LPDIRECT3DDEVICE9 device, std::string filename) 
{ 
D3DXCreateSprite(device, &sprite); 
D3DXCreateTextureFromFileEx(device, filename.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0xFFFF00FF, NULL, NULL, &texture); 

D3DXIMAGE_INFO imageInfo; 
D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo); 

height = (float)imageInfo.Height; 
width = (float)imageInfo.Width; 

return true; 
    } 


    void Sprite::render(LPDIRECT3DDEVICE9 pDevice, int alpha) 
    { 

alpha = (int)(255*((float)alpha/100)); 
D3DXMATRIX scaleMatrix; 
D3DXMATRIX transMatrix; 
D3DXMatrixScaling(&scaleMatrix, scale.x, scale.y, scale.z); 
D3DXMatrixTranslation(&transMatrix, position.x, position.y, position.z); 

D3DXMatrixMultiply(&transMatrix, &scaleMatrix, &transMatrix); 
sprite->SetTransform(&transMatrix); 

sprite->Begin(D3DXSPRITE_ALPHABLEND); 
sprite->Draw(texture, NULL, NULL, NULL, D3DCOLOR_RGBA(255,255,255,alpha)); 
sprite->End(); 

    } 


    void Sprite::setPosition(int x, int y){ 
    position.x = (float)x; 
    position.y = (float)y; 
    position.z = 0.0f; 
    } 


    void Sprite::setSize(int newWidth, int newHeight) 
     { 

     scale.x = (float)newWidth/width; 
     scale.y = (float)newHeight/height; 
     scale.z = 0; 
     } 


    int Sprite::getWidth(){ 
    return (int)width; 
    } 

    int Sprite::getHeight(){ 
    return (int)height; 
    } 

    void Sprite::OnLostDevice() 
    { 
    sprite->OnLostDevice(); 
    } 

    void Sprite::OnResetDevice() 
    { 
    sprite->OnResetDevice(); 
    } 

여기에 처리됩니다

void OnLostDevice(void *pContext) 
    { 
    gFont -> LostDevice(); 
    TitleScreen->OnLostDevice(); 
    D3DManager::Get()->ReleaseScene(); 

    } 

    void OnResetDevice(void *pContext) 
    { 
    TitleScreen->OnResetDevice(); 
    gFont -> ResetDevice(); 
    D3DManager::Get()->ResetScene(); 
    } 

창 크기를 조정할 때 트리거 브레이크 :

case WM_EXITSIZEMOVE: 
    GetClientRect(mhWnd, &clientRect); 
    md3dParams.BackBufferWidth = clientRect.right; 
    md3dParams.BackBufferHeight = clientRect.bottom; 
    mpOnLostDevice(mpResetAndLost); 
    **if(FAILED(mpd3dDevice->Reset(&md3dParams))) 
     MPOD_ASSERT(false);** 
    mpOnResetDevice(mpResetAndLost); 
    return 0; 

답변

1

나는 충돌 게임을 TitleScreen-> OnLostDevice (의 스프라이트)하지만 위의 용액으로 협력 수준을 테스트 스프라이트 클래스

도 아니었다 질감을 멈춘 방출하지만 엉망이되었다 각 크기로 자산을 분해하여

1

기기를 재설정해야하는지 여부를 테스트해야합니다. TestCooperativeLevel을 사용하는 것이 좋습니다.

E.G.

if(HRESULT(mpd3dDevice->TestCooperativeLevel())) 
    { 
    if(FAILED(mpd3dDevice->Reset(&md3dParams))) 
    MPOD_ASSERT(false); 
    } 
관련 문제