Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

07.04.2009, 17:41

Problem mit Vertex-Indexbuffern

Hi,

nachdem ich mein Programm fürs Erstellen des Terrains komplett überarbeitet hab (hat vorher funktioniert) tauchen nun einige Probleme auf die ich auch nach mehrmaligem Vergleichen des Codes nicht entdecken kann

Code:

C-/C++-Quelltext

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
float g_fTime = 0.0f;

SDirect3DParameters f_3DParameters;

struct sVertex
{
    tbVector3 Position;
};

PDIRECT3DVERTEXBUFFER9 VertexBuffer;
PDIRECT3DINDEXBUFFER9 IndexBuffer;


sVertex* Vertices;
WORD* Indices;

const int Resolution = 16;

int IndexCreationLoop = 0;

#define VERTEXFORMAT D3DFVF_XYZ

WORD GetVertexIndex(WORD x, WORD y)
{
    return y * Resolution + x;
}

tbResult InitScene()
{

    HRESULT hResult;

    int Aspect = f_3DParameters.VideoMode.Width / f_3DParameters.VideoMode.Height;


    tbMatrix Projection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),(float)(Aspect),0.1f,100.0f);

    g_pD3DDevice->SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)(&Projection));

    g_pD3DDevice->SetFVF(VERTEXFORMAT);
    g_pD3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);


    int NumVertices = Resolution * Resolution;

        if(FAILED(hResult = g_pD3DDevice->CreateVertexBuffer(NumVertices * sizeof(sVertex),0,VERTEXFORMAT,D3DPOOL_MANAGED,&VertexBuffer,NULL)))
    {
        MessageBox(NULL,"FEHLER","FEHLER",MB_OK);
    }

    int NumIndices = (Resolution-1) * (Resolution-1) * 6;

        if(FAILED(hResult = g_pD3DDevice->CreateIndexBuffer(NumIndices * sizeof(WORD),0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&IndexBuffer,NULL)))
    {
        MessageBox(NULL,"FEHLER","FEHLER",MB_OK);
    }

    VertexBuffer->Lock(0,0,(void**)(&Vertices),D3DLOCK_NOSYSLOCK);
    IndexBuffer->Lock(0,0,(void**)(&Indices),D3DLOCK_NOSYSLOCK);


        for(WORD x = 0; x < Resolution; x++)
    {
        for(WORD y = 0; y < Resolution; y++)
        {

                sVertex Temp;

                Temp.Position.x = ((float)(x) / (float)(Resolution -1.0f) -1.0f) * 200.0f;
                Temp.Position.y = 0.0f;
                Temp.Position.z = ((float)(-y) / (float)(Resolution -1.0f) +1.0f)*200.0f;
                
                Vertices[GetVertexIndex(x,y)] = Temp;
            }
    }

    VertexBuffer->Unlock();


        for(int x = 0;x < Resolution - 1;x++)
    {
        for(int y = 0;y < Resolution -1;y++)
        {
            
            Indices[IndexCreationLoop] = GetVertexIndex(x,y);
            IndexCreationLoop += 1;
            Indices[IndexCreationLoop] = GetVertexIndex(x+1,y);
            IndexCreationLoop += 1;
            Indices[IndexCreationLoop] = GetVertexIndex(x,y+1);
            IndexCreationLoop += 1;
            Indices[IndexCreationLoop] = GetVertexIndex(x,y+1);
            IndexCreationLoop += 1;
            Indices[IndexCreationLoop] = GetVertexIndex(x+1,y);
            IndexCreationLoop += 1;
            Indices[IndexCreationLoop] = GetVertexIndex(x+1,y+1);
            IndexCreationLoop += 1;
        }
    }


    IndexBuffer->Unlock();




    return TB_OK;

}


tbResult render(float fNumSecsPassed)
{
    HRESULT Result;

    g_pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_TARGET,D3DCOLOR_XRGB(30,60,90),1.0f,0);

    g_pD3DDevice->BeginScene();

    g_pD3DDevice->SetStreamSource(0,VertexBuffer,0,sizeof(sVertex));
    g_pD3DDevice->SetIndices(IndexBuffer);

    Result = g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
                                                 0,
                                                 0,
                                                 Resolution*Resolution,
                                                 0,
                                                 (Resolution-1)*(Resolution-1)*2);

    if (FAILED(Result))
    {
        MessageBox(NULL,"FEHLER","FEHLER",MB_OK);
    } 


    g_pD3DDevice->EndScene();

    g_pD3DDevice->Present(NULL,NULL,NULL,NULL);

    return TB_OK;
}

tbResult move(float fNumSecsPassed)
{
    g_fTime += fNumSecsPassed;

    return TB_OK;
}

tbResult ClearAll(bool ErrorCancel)
{
    if(ErrorCancel)
    {

    }
    ExitDirect3D();
    ExitWindow();
    tbExit();

    return TB_OK;
}



Sorry wenn er vielleicht etwas "seltsam" aussieht, ist nur provisorisch entstanden.


Folgender Fehler tritt bei jedem Aufruf von DrawIndexPrimitive auf:

Eine Ausnahme (erste Chance) bei 0x76b5f35f in TerrainTest2.exe: Microsoft C++-Ausnahme: long an Speicherposition 0x0051f470.

Vorher hat Windows sogar 200MB Fehlerberichterstattungen erstellt und mein PC hat nicht mehr reagiert o0.



Irgendwas stimmt mit meinem Vertex oder Indexbuffer nicht, ich hab jedoch den Code mehrmals verglichen komme jedoch nicht auf den entscheidenen Punkt :\.



Hoffe mir kann jemande helfen :>.

2

07.04.2009, 18:47

Hast du beim Aufruf von DrawIndexPrimitive mal fixe Werte ausprobiert?

Bitte demnächst C++ Codetags verwenden
fka tm

Anonymous

unregistriert

3

07.04.2009, 18:51

Hallo Dustin B.,
da scheint was mit der Speicherablagerung nicht zu passen. Schau mal, ob beim laden des Terrains alle Daten ok sind und nichts vorzeitig terminiert wird. Irgendwo in deinem Code-wirwarr werden wohl falsche oder nicht vorhandene Speicheradressen aufgesucht.

4

07.04.2009, 19:54

W T F O_o

Der Fehler lag an einem vergessenem InitScene()^^ *schäm*


Trotzdem vielen Dank für eure Hilfe

Werbeanzeige