Direkter Zugriff auf Oberflaeche // Access-Violation
-
Fehlermeldung:
First-chance exception at 0x00c72548 in DirectXSurfaces.exe: 0xC0000005: Access violation writing location 0x000000a4.
Relevanter Code aus der Main.cpp:
case WM_PAINT: D3DCOLOR TextColor = D3DCOLOR_XRGB(0xFF,0,0); Direct3D.BeginScene(); StarField.Draw(Direct3D.GetBackbuffer()); Direct3D.DrawText("Test",100,100,D3DCOLOR_XRGB(0,0,0)); Direct3D.EndScene(); break;Relevanter Code aus der StarField.cpp:
void CStarField::Draw(LPDIRECT3DSURFACE9 lpSurface) { D3DLOCKED_RECT LockedRect; //lock access to the surface lpSurface->LockRect(&LockedRect,NULL,0); int Pitch = LockedRect.Pitch / 4; //if the lock was successful, lpSurface is a legit pointer to the surface D3DCOLOR* Pixels = (D3DCOLOR*)LockedRect.pBits; for(int i=0;i<m_NumberOfStars;i++) { m_Stars[i].Draw(Pixels,Pitch); m_Stars[i].Move(); } //important release surface lpSurface->UnlockRect(); }Relevanter Code aus der Star.cpp:
void CStar::Draw(D3DCOLOR* Pixels, int Pitch) { //calculate star position int index = ((int)m_y * Pitch + (int)m_x); //starcolors //take length into consideration and chose color for(int i=0;i<m_length;i++) { Pixels[index + i * Pitch] = D3DCOLOR_XRGB(112+i*16,112+i*16,112+i*16); } }Anmerkungen!!!
Selbst wenn ich m_Stars[i].Draw(Pixels,Pitch); aus der StarField.cpp auskommentiere, bekomme ich keine Fehlermeldungen. Wenn ich dann irgendeine Methode, die versucht, auf einen der Pixel zuzugreifen, hinzufuege, spuckt die Console wieder Fehlermeldungen aus.
-
'DirectXSurfaces.exe': Loaded 'D:\Users\ICH\Documents\Visual Studio 2010\Projects\DirectXSurfaces\Debug\DirectXSurfaces.exe', Symbols loaded.
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\d3d9.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\d3d8thk.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\D3DX9_43.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\aticfx32.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\atiu9pag.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\atiumdag.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\atiumdva.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Unloaded 'C:\Windows\SysWOW64\atiumdva.dll'
'DirectXSurfaces.exe': Unloaded 'C:\Windows\SysWOW64\atiumdag.dll'
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\atiumdag.dll', Cannot find or open the PDB file
'DirectXSurfaces.exe': Loaded 'C:\Windows\SysWOW64\atiumdva.dll', Cannot find or open the PDB file
First-chance exception at 0x00c72548 in DirectXSurfaces.exe: 0xC0000005: Access violation writing location 0x000000a4.
Der Fehler ca. 200 mal
...
...
...
...
The thread 'Win32 Thread' (0xa1c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xb4c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xa80) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1140) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x109c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x12ec) has exited with code 0 (0x0).
The program '[4484] DirectXSurfaces.exe: Native' has exited with code 0 (0x0).
-
ich würde mal sagen, du schreibst da in bereich, der dir nicht gehört.
-
Aber wieso? Ich locke ein Rechteck aus dem Backbuffer und moechte dann den einen oder anderen Pixel aendern und das Rechteck wieder freigeben...
-
So, habe eben das erste mal den Debugger laufen lassen und dabei kam es yu folgendem Ergebnis:
http://u89t.img-up.net/starfield1dw1g.jpg
scheinbar laesst sich der backgroundbuffer nicht richtig oeffnen oder zumindest nicht das rechteck darin...
Ausserdem wundert es mich, dass i einen negativen Wert hat?Dabei ist das der erste Methoden-Aufruf
-
Returncodes von Funktionen sind dazu da dass man sie auswertet.
Versuch das mal mit dem Returncode von LockRect().
Returncode ausgeben, googeln, verstehen, Programm entsprechend ändern, funktioniert.
-
Das HRESULT ist -2005530516 ich finde dazu aber nichts...
