IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

DirectX Discussion :

probleme lors de la creation du device


Sujet :

DirectX

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 44
    Points : 23
    Points
    23
    Par défaut probleme lors de la creation du device
    Salut !
    J'essai d'afficher un écran bleu en plein écran mais le programme plante en me disant : "Unhandled exception at 0x0040126e in loader3ds DX 9.0c.exe: 0xC0000005: Access violation reading location 0x00000000."
    j'ai lancé le debugger et la variable IDirect3DDevice9 *myIDirect3DDevice9 a une valeur nulle. Le compilateur s'arrete sur la méthode clear de la méthode de rendu. Cette méthode de rendu une fois mise en commentaire permet au programme de ne pas planter. Que puis je faire ?
    voici un peu de code (a la fin le winMain) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    class direct3dApp
    {
    private :
    	//manageWindow myWindow ;
    	IDirect3D9 *D3dDevice ;//cré un device
    	IDirect3DDevice9 *myIDirect3DDevice9 ;
    public:
    	direct3dApp();
    	void deviceCreation();
    	void rendering();
    	void freeD3d();//mettre un destructeur a la place
     
    };
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    hResult=D3dDevice->CreateDevice(D3DADAPTER_DEFAULT,      D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
                              &presentParameters,
                              &myIDirect3DDevice9);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    void direct3dApp::rendering()
    {
    	myIDirect3DDevice9->Clear(0,
                              NULL,
                              D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER, r
                              0x000000EE, //Colour to clear to (AARRGGBB)
                              1.0f,  0 ); 
    	myIDirect3DDevice9->BeginScene() ;
    	myIDirect3DDevice9->EndScene() ;
    	myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	myWindow = new manageWindow() ;
    	direct3dApp *myDirect3dApp = new direct3dApp() ;
     
    	myWindow->createWindow(hInstance);
    	ShowCursor(FALSE);
    	myDirect3dApp->deviceCreation();
    	MSG msg;
    	while(1)
    	{
     
    		if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) 
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		myDirect3dApp->rendering();
     
    		if( myWindow->getCloseWindow() )
    			return 0;
    	}
    }

  2. #2
    Membre averti Avatar de Bob.Killer
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    336
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 336
    Points : 332
    Points
    332
    Par défaut
    On voit pas tt le code et je ne sais pas exactement ou cela peu planter... peu être ta structure de fenêtre qui est mal initialisé ou sinon ta carte ne supporte pas le mode hardware

    Init de direct3D :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    IDirect3D9 *D3dDevice; ;//cré un objet direct3D
    IDirect3DDevice9 *myIDirect3DDevice9 ; ;//cré un device
    donc ensuite il faut faire ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    // Création de l'objet Direct3D
    if( NULL == ( D3dDevice = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;
    Ne pas oublier d'initialisé les données de la structure pour la fenêtre :
    (On est pas oubligé de mettre tout mais bon...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
     
    d3dpp.BackBufferWidth = (UINT)SizeX; // SizeX = largeur de fenêtre passée à CreateWindow
    d3dpp.BackBufferHeight = (UINT)SizeY; // SizeY = hauteur de fenêtre passée à CreateWindow
    d3dpp.hDeviceWindow = hWnd;   // hWnd = handle de la fenêtre renvoyé par CreateWindow
    d3dpp.Windowed = TRUE;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
    d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    Et enfin il faut faire attention lors de la création du device car la carte peu ou pas supporter le mode hardware :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    // Création du Device de Direct3D
    D3DCAPS9 Caps;
    HRESULT s = D3dDevice->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &Caps);
    UINT   flag = D3DCREATE_SOFTWARE_VERTEXPROCESSING, devtype = D3DDEVTYPE_REF;
     
    if (SUCCEEDED(s) && Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
    {
          flag = D3DCREATE_HARDWARE_VERTEXPROCESSING;
          devtype = D3DDEVTYPE_HAL;
    }
     
    if( FAILED( D3dDevice->CreateDevice( D3DADAPTER_DEFAULT, (D3DDEVTYPE)devtype, hWnd,
                                          flag,
                                          &d3dpp, &myIDirect3DDevice9) ) )
    {
        return E_FAIL;
    }
    J'espère que ça t'aidera...
    Pensez aux tutoriels programmation : http://programmation.developpez.com/cours-tutoriels/

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 44
    Points : 23
    Points
    23
    Par défaut
    Pour le mode hardware, j'ai une carte direcX 9, ça devrait être bon ?
    Je met tout le code (y compris ce qui est déjà au dessus), vous pouvez le copier/coller dans visual pour y voir plus clair:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
     
    #include <Windows.h>
    #include<iostream>
    #include "d3d9.h"
    using namespace std;
     
    #pragma comment( lib,"d3d9.lib")
     
     
    LRESULT CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam);
     
    class manageWindow
    {
    private:
    	HWND hWnd;//handler window
    	bool closeWindow ;
    public:
    	manageWindow();
    	void createWindow(HINSTANCE hInstance);
    	//HWND getHwnd() ;
    	bool getCloseWindow();
    	void setCloseWindow(bool myBoolValue);
    };
     
    manageWindow *myWindow ;
    HWND hWnd;//handler window
     
    class direct3dApp
    {
    private :
    	//manageWindow myWindow ;
    	IDirect3D9 *D3dDevice ;//cré un device
    	IDirect3DDevice9 *myIDirect3DDevice9 ;
    public:
    	direct3dApp();
    	void deviceCreation();
    	void rendering();
    	void freeD3d();//mettre un destructeur a la place
     
    };
     
    direct3dApp::direct3dApp()
    {
    	D3dDevice=NULL;
    	myIDirect3DDevice9=NULL ;
    	D3dDevice = Direct3DCreate9(D3D_SDK_VERSION);
       /*if(!D3dDevice)
       {
          //Handle error
       }*/
    }
     
    void direct3dApp::deviceCreation()
    {
     
    	D3DFORMAT format=D3DFMT_A8R8G8B8;//D3DFMT_R5G6B5; 
    	D3DPRESENT_PARAMETERS presentParameters;
    	HRESULT hResult;
     
        //met à zéro tout les champs du pointeur sur structure
        ZeroMemory(&presentParameters,sizeof(D3DPRESENT_PARAMETERS));
     
    	presentParameters.BackBufferCount= 1;       presentParameters.MultiSampleType=D3DMULTISAMPLE_NONE;     presentParameters.MultiSampleQuality=0;              
        presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; 
    	presentParameters.hDeviceWindow = hWnd;      presentParameters.Flags=0;      
        presentParameters.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; 
        presentParameters.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE; 
        presentParameters.BackBufferFormat=format;      //Display format
        presentParameters.EnableAutoDepthStencil=FALSE; 	
    	  hResult=D3dDevice->CreateDevice(D3DADAPTER_DEFAULT,      D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, 
                              &presentParameters, 
                              &myIDirect3DDevice9); 
       if(FAILED(hResult))
       {}
    }
     
    void direct3dApp::rendering()
    {
    	myIDirect3DDevice9->Clear(0, NULL, 
                              D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,                            0x000000EE, //Colour to clear to (AARRGGBB)
                              1.0f,    0 ); 
    	myIDirect3DDevice9->BeginScene() ;
    	myIDirect3DDevice9->EndScene() ;
    	myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);
    }
     
    void direct3dApp::freeD3d()
    {
    	if(D3dDevice)
    	{
          D3dDevice->Release();
          D3dDevice=NULL;
        }
    }
     
    /*HWND manageWindow::getHwnd()
    {
    	return hWnd ;
    }*/
     
     
     
    manageWindow::manageWindow()
    {
    	closeWindow=false ;
    }
     
    bool manageWindow::getCloseWindow()
    {
    	return closeWindow ;
    }
     
    void manageWindow::setCloseWindow(bool myBoolValue)
    {
    	closeWindow = myBoolValue ;
    }
     
    void manageWindow::createWindow(HINSTANCE hInstance)
    {
    	WNDCLASS hWindow;
    	//hWindow.cbSize=sizeof(WNDCLASSEX);
    	hWindow.style=CS_HREDRAW|CS_VREDRAW;
    	hWindow.lpfnWndProc=MainProc;
    	hWindow.cbClsExtra=0;
    	hWindow.cbWndExtra=0;
    	hWindow.hInstance=hInstance;
    	hWindow.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    	hWindow.hCursor=LoadCursor(NULL,IDC_ARROW);
    	hWindow.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    	hWindow.lpszMenuName=NULL;
    	hWindow.lpszClassName="stdWindow";
    	//hWindow.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    	RegisterClass(&hWindow);
     
    	int wWidth=GetSystemMetrics(SM_CXSCREEN);//window width= resolution du bureau
        int wHeight=GetSystemMetrics(SM_CYSCREEN);
     
    	HWND hWnd;//handler window
    	hWnd=CreateWindow(
    		"stdWindow",
    		"DirectX",
    		WS_POPUP|WS_VISIBLE ,
    		0,
    		0,//(0,0) origine en haut à gauche
    		wWidth,
    		wHeight,//résolution du bureau
    		NULL,
    		NULL,
    		hInstance,
    		NULL
    		);
    	ShowWindow(hWnd,SW_SHOW);
    }
     
     
     
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	myWindow = new manageWindow() ;
    	direct3dApp *myDirect3dApp = new direct3dApp() ;
     
    	myWindow->createWindow(hInstance);
    	ShowCursor(FALSE);
    	myDirect3dApp->deviceCreation();
    	MSG msg;
    	while(1)
    	{
     
    		if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) 
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		myDirect3dApp->rendering();
     
    		if( myWindow->getCloseWindow() )
    			return 0;
    	}
    }
     
    LRESULT CALLBACK MainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
     
    	HDC hDC;
    	PAINTSTRUCT paintst;
     
    	switch (message)
    	{
    	/*case WM_PAINT:
    		hDC=BeginPaint(hWnd,&paintst);
    		EndPaint(hWnd,&paintst);
    		return 0;*/
    	case WM_KEYDOWN:
    	case WM_DESTROY:
    		myWindow->setCloseWindow(true) ;
    		PostQuitMessage(0);
    		return 0;
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    }

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 44
    Points : 23
    Points
    23
    Par défaut
    j'ai essayé la ligne :

    if( NULL == ( D3dDevice = Direct3DCreate9( D3D_SDK_VERSION ) ) )
    return E_FAIL;

    mais mon plante toujours au meme endroit c'est a dire dans la méthode "rendering"

  5. #5
    Membre averti Avatar de Bob.Killer
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    336
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 336
    Points : 332
    Points
    332
    Par défaut
    re...

    g testé ton code et en métant ça, ça marche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    void direct3dApp::rendering() 
    { 
    	if(myIDirect3DDevice9 != NULL)
    	{
       myIDirect3DDevice9->Clear(0, NULL, 
                              D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,                            0x000000EE, //Colour to clear to (AARRGGBB) 
                              1.0f,    0 ); 
       myIDirect3DDevice9->BeginScene() ; 
       myIDirect3DDevice9->EndScene() ; 
       myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL); 
    	}
    }
    en fait il faut utiliser les retours des fonctions direct3D pour pas programmer à la truelle... car si le device est nulle faut pas que tu l appel ! je sais pas pk il l appel avant la création du device, mais c ce qui fait tt planter !
    Pensez aux tutoriels programmation : http://programmation.developpez.com/cours-tutoriels/

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 44
    Points : 23
    Points
    23
    Par défaut
    ok merci a toi !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme lors de la creation d'un fichier d'installation VB6
    Par Esmax666 dans le forum Installation, Déploiement et Sécurité
    Réponses: 6
    Dernier message: 29/06/2009, 14h41
  2. [VBA] probleme lors de la creation d'un fichier
    Par tiotel dans le forum Access
    Réponses: 3
    Dernier message: 09/08/2006, 15h00
  3. [VBA-E]probleme lors de la creation de feuille
    Par lcoder dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 15/06/2006, 19h51
  4. Réponses: 2
    Dernier message: 21/04/2006, 15h08
  5. probleme lors de la creation de table
    Par perlgirl dans le forum Requêtes
    Réponses: 2
    Dernier message: 17/11/2005, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo