RazzorFlame Temat założony przez niniejszego użytkownika |
Program działa jedynie w debuggerze - inaczej się crashuje. » 2014-09-29 21:02:04 Witam. Przejde od razu do problemu. Kod: #include <v3de.hpp> #include <fstream>
#pragma comment(lib, "user32.lib") #pragma comment(lib, "gdi32.lib") #pragma comment(lib, "d3d11.lib") #pragma comment(lib, "d3dx11.lib") #pragma comment(lib, "d3dx10.lib") #pragma comment(lib, "dxerr.lib")
#include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> #include <xnamath.h> #include <DxErr.h> #include <string>
HRESULT hr;
v3de::WindowClass vWClass; v3de::DX11Window * vWindow; ID3D11Buffer * triangleVertBuffer = NULL; v3de::VertexModel model; v3de::KeyManager kmgr;
int Width = 800; int Height = 600;
v3de::Scene scene;
int main( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { vWClass.create( "KlasaOkna", true, v3de::uVector3 < unsigned char >( 255, 0, 0 ), CS_HREDRAW | CS_VREDRAW ); vWindow = new v3de::DX11Window(); vWindow->create( "Okienko", "KlasaOkna", WS_OVERLAPPEDWINDOW, v3de::uVector < int >( Width, Height ), true ); vWindow->show( true ); vWindow->setWindowMode( true ); vWindow->dxGetCamera()->setWindowSize( v3de::uVector < int >( Width, Height ) ); vWindow->createVertexShader( "Effects.fx" ); vWindow->createPixelShader( "Effects.fx" ); vWindow->createVertexLayout(); v3de::VertexModel * model = new v3de::VertexModel; model->addVertex( v3de::Vertex( - 1.0f, - 1.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 1.0f ) ); model->addVertex( v3de::Vertex( - 1.0f, + 1.0f, - 1.0f, 0.0f, 1.0f, 0.0f, 1.0f ) ); model->addVertex( v3de::Vertex( + 1.0f, + 1.0f, - 1.0f, 0.0f, 0.0f, 1.0f, 1.0f ) ); model->addVertex( v3de::Vertex( + 1.0f, - 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f ) ); model->addVertex( v3de::Vertex( - 1.0f, - 1.0f, + 1.0f, 0.0f, 1.0f, 1.0f, 1.0f ) ); model->addVertex( v3de::Vertex( - 1.0f, + 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f ) ); model->addVertex( v3de::Vertex( + 1.0f, + 1.0f, + 1.0f, 1.0f, 0.0f, 1.0f, 1.0f ) ); model->addVertex( v3de::Vertex( + 1.0f, - 1.0f, + 1.0f, 1.0f, 0.0f, 0.0f, 1.0f ) ); model->addIndices( 6, 0, 1, 2, 0, 2, 3 ); model->addIndices( 6, 4, 6, 5, 4, 7, 6 ); model->addIndices( 6, 4, 5, 1, 4, 1, 0 ); model->addIndices( 6, 3, 2, 6, 3, 6, 7 ); model->addIndices( 6, 1, 5, 6, 1, 6, 2 ); model->addIndices( 6, 4, 0, 3, 4, 3, 7 ); model->setPath( "model.vvv" ); v3de::VertexModel * model2 = new v3de::VertexModel; model2->addVertex( v3de::Vertex( - 0.7f, - 0.7f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f ) ); model2->addVertex( v3de::Vertex( - 0.7f, - 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ) ); model2->addVertex( v3de::Vertex( - 0.5f, - 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f ) ); model2->addVertex( v3de::Vertex( - 0.5f, - 0.7f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ) ); model2->addIndex( 0 ); model2->addIndex( 1 ); model2->addIndex( 2 ); model2->addIndex( 0 ); model2->addIndex( 2 ); model2->addIndex( 3 ); model2->setPath( "model2.vvv" ); scene.addModel( model ); scene.addModel( model2 ); v3de::Object3D obj; obj.xmvRotationAxis = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); obj.xmmRotation = XMMatrixRotationAxis( obj.xmvRotationAxis, 0.0f ); obj.xmmScale = XMMatrixScaling( 1.0f, 1.0f, 1.0f ); obj.xmmTranslation = XMMatrixTranslation( 0.0f, 0.0f, 0.0f ); obj.filepath = "model.vvv"; v3de::Object3D obj2; obj2.xmvRotationAxis = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); obj2.xmmRotation = XMMatrixRotationAxis( obj2.xmvRotationAxis, 0.0f ); obj2.xmmScale = XMMatrixScaling( 1.0f, 1.0f, 1.0f ); obj2.xmmTranslation = XMMatrixTranslation( 0.0f, 0.0f, 0.0f ); obj2.filepath = "model.vvv"; scene.addObject( & obj ); scene.addObject( & obj2 ); scene.init( vWindow ); vWindow->setViewport( v3de::uVector < int >( 800, 600 ) ); vWindow->dxGetCamera()->setPosition( v3de::uVector3 < float >( 0.0f, 3.0f, - 8.0f ) ); vWindow->dxGetCamera()->setTarget( v3de::uVector3 < float >( 0.0f, 0.0f, 0.0f ) ); vWindow->dxGetCamera()->setUp( v3de::uVector3 < float >( 0.0f, 1.0f, 0.0f ) ); vWindow->dxGetCamera()->update(); vWindow->dxGetCamera()->setProjectionFOV( 0.4f ); float rot = 0; while( vWindow->isReachable() ) { vWindow->pollEvent(); v3de::Message ms = vWindow->getWindowEvent(); if( ms.type == v3de::Message::Unknown ) { vWindow->clearWindow( D3DXCOLOR( 255, 0, 0, 0.0f ) ); scene.draw( vWindow ); vWindow->drawScene(); } if( ms.type == v3de::Message::Closed ) { vWindow->destroy(); break; } else if( ms.type == v3de::Message::KeyDown ) { if( ms.key == v3de::Key::Escape ) { vWindow->destroy(); break; } } else if( ms.type == v3de::Message::MouseMoved ) { v3de::uVector < int > ms = v3de::Mouse::getPosition( * vWindow ); v3de::Vertex msv; msv.setPosition( ms.x, ms.y, 0 ); cout << v3de::Vertex::toDirectX11( msv, 800, 600 ).position.x << "/" << v3de::Vertex::toDirectX11( msv, 800, 600 ).position.y << endl; } } delete vWindow; vWClass.unRegister(); return 0; }
Program crashuje się dokładnie w tej linijce: vWindow = new v3de::DX11Window();To jest dla mnie dziwne, ponieważ tak wygląda konstruktor klasy DX11Window oraz Window (klasy podstawowej) DX11Window::DX11Window() : Window() { d3d11Device = NULL; d3d11SwapChain = NULL; d3d11DeviceContext = NULL; d3d11RenderTargetView = NULL; d3d11DepthStencilView = NULL; d3d11DepthStencilBuffer = NULL; d3d11VertexLayout = NULL; cbPerObjectBuffer = NULL; } Window::Window() { uStyle = 0; visible = false; windowed = true; reachable = false; focus = false; }
Sprawdzałem "cout-ami" do którego momentu program dochodzi i okazuje się że przechodzi cały konstruktor Window a przed "d3d11Device = NULL;" się kraszuje. Nie wiem już o co biega. NAJGORSZE JEST TO ŻE KIEDY URUCHOMIE TO DEBUGGEREM TO WSZYSTKO GRA I BUCZY. Edit: Problem nieaktualny, nie jest w tym problem tylko w tym idiotycznym xnamath. Teraz czytam że tam XMVECTOR i XMMATRIX są dopasowane (czy jak to się tam mówi) do 16 bitów, dlatego program się kraszuje. Jest dużo artykułów na ten temat więc nie zawracam Wam głowy. Poradzę sobie. |