D3D - GetSurfaceLevel unhandled exception - c++

I'm creating D3D cursor, so first I made Surface & Texture.
and doing this, I met error on GetSurfaceLevel() Function.
Unhandled exception at 0x5B494B11
0xC0000005: Access violation reading location 0x00000000.
code:
D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );
g_D3dDevice->ShowCursor( TRUE );
What should I do?

Unhandled exception at 0x5B494B11 0xC0000005: Access violation reading location 0x00000000.
This kind of error was caused by dereference a NULL pointer, check whether you have create the texture successfully. Make sure g_cursortex not NULL before calling g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
HRESULT hr = D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
if (SUCCEEDED(hr))
{
g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );
}

Related

Access Violation during MFC execution of CFrameWnd::InitialUpdateFrame

I am in the process of trying to upgrade a VC++ 6.0 project to the latest version and am running into an issue. The program starts up fine but in the process of creating two child windows within the main view it crashes with an access violation. When run in debug mode it cannot find the exact location where the error occurs, displaying "Frame not in module" and "The current stack frame was not found in a loaded module. Source cannot be shown for this location" making it difficult to pinpoint the exact issue.
Going through the program step by step reveals that the error lies in the call of
CFrameWnd::InitialUpdateFrame.
From there it goes into the following functions:
Main.cpp:
frame->InitialUpdateFrame(dc, TRUE);
winfrm.cpp:
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
afxwin2.inl:
CWnd::SendMessageToDescendants(m_hWnd, message, wParam, lParam, bDeep, bOnlyPerm);
wincore.cpp:
SendMessageToDescendants(hWndChild, message, wParam, lParam, bDeep, bOnlyPerm);
(Recursion to same function, error occurs on second recursion)
wincore.cpp:
AfxCallWndProc(pWnd, pWnd->m_hWnd, message, wParam, lParam);
Error has occurred at 3 of the following locations:
wincore.cpp:
_AfxPreInitDialog(pWnd, &rectOld, &dwStyle);
lResult = pWnd->WindowProc(nMsg, wParam, lParam);
_AfxPostInitDialog(pWnd, rectOld, dwStyle);
It is called from this function (simplified):
CDocument* XApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
doc_x_spc *dc =
static_cast<doc_x_spc *> ( m_spc_template->CreateNewDocument() );
CMDIChildWnd *frame =
static_cast<CMDIChildWnd *> ( m_spc_template->CreateNewFrame(dc, NULL) );
if ( !dc->OnOpenDocument(lpszFileName) )
{
AfxMessageBox( IDS_SPCOPENERROR, MB_OK, NULL );
return NULL;
}
CString raw(lpszFileName);
dc->set_raw_file(raw);
frame->InitialUpdateFrame(dc, TRUE);
if (app_multiplexed == SINGLE)
menu.LoadMenu(IDR_REMPLETYPE_SINGLE);
else
menu.LoadMenu(IDR_REMPLETYPE);
CMainFrame* pMainFrame = (CMainFrame *)m_pMainWnd;
pMainFrame->MDISetMenu(&menu, NULL);
return dc;
}
The access violation produces this exact error:
Exception thrown at 0x01144008 in X.exe: 0xC0000005: Access violation executing location 0x01144008.
Would appreciate any help. Thank you!

Unhandled Exception at igd10iumd32.dll

Seems like I'm getting an unhandled exception related to the graphics when working on my project in Visual Studio.
I updated the graphics drivers recently, due to Windows 10. It seems like since then these problems happen. It's not on my code, as I've been on and on changing it trying to fix it for full days with no avail. This is a devastating problem.
I've eventually downgraded my Intel graphics driver in attempt to fix this issue, but nichts.
What am I doing wrong?
This is the code I get:
Unhandled exception at 0x657F994A (igd10iumd32.dll) in Game.exe: 0xC0000005: Access violation reading location 0x00000158.
Apparently I don't have enough reputation to comment, so I'll just post this as an answer.
I'm having the same issue. I also upgraded from Windows 7 to 10. My laptop has both integrated and dedicated graphics cards, but the preferred graphics card is a NVIDIA GeForce 710m. I thought that I only needed to upgrade my drivers, but after upgrading my driver from 340.52 to the latest (353.62), my problem still persisted.
Below is a sample 'hello world' program that reproduces the program on my machine. It's seemly random - it may happen in the 2nd loop, or the 279th.
#include "sdl/SDL.h"
#include "sdl/SDL_syswm.h"
int main( int argc, char*argv[] )
{
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
return 1;
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 0 );
SDL_Window* sdlWindow = SDL_CreateWindow(
"tac",
30, 60,
1366, 768,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
if( !sdlWindow )
return 1;
SDL_GLContext mainContext = SDL_GL_CreateContext( sdlWindow );
if( !mainContext )
return 1;
while( true )
{
SDL_Event mySDLevent;
while( SDL_PollEvent( &mySDLevent ) )
{
}
SDL_GL_SwapWindow( sdlWindow ); // <-- it crashes here
}
SDL_GL_DeleteContext( mainContext );
SDL_DestroyWindow( sdlWindow );
SDL_Quit();
return 0;
}
First-chance exception at 0x5ECB9958 (igd10iumd32.dll) in MyGame.exe: 0xC0000005: Access violation writing location 0x77007B85.
Unhandled exception at 0x5ECB9958 (igd10iumd32.dll) in tacMain.exe: 0xC0000005: Access violation writing location 0x77007B85.
My callstack comes from these dlls
igd10iumd32.dll
nvoglv32.dll
kernel32.dll
ntdll.dll
So I assume it's a driver issue?...

Access violation at SDL_CreateRenderer

I use vc++ 2010 express and currently working on a project but when I try to use SDL_CreateRenderer function I get this error:
First-chance exception at 0x6c8037be in Oyun Projem.exe: 0xC0000005: Access violation reading location 0x00000010.
Unhandled exception at 0x6c8037be in Oyun Projem.exe: 0xC0000005: Access violation reading location 0x00000010.
The program '[320] Oyun Projem.exe: Native' has exited with code -1073741819 (0xc0000005).
at this line:
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
here is the code
#include "stdafx.h"
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window;
SDL_Renderer *renderer;
window = NULL;
window = SDL_CreateWindow("My first RPG!", 100, 100, 100, 100, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
return 0;
}
Here is what I see when debugging:
SDL_CreateWindow returns NULL if there is a failure. Your code needs to check for this.
// Your code:
window = SDL_CreateWindow("My first RPG!", 100, 100, 100, 100, SDL_WINDOW_SHOWN);
// Add the following:
// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}

Send return value to dialog from thread MFC

I'm creating dialog with do modal:
MainHamsterDlg MainHamsterDlg;
if (MainHamsterDlg.DoModal() == IDCANCEL)
break;
Then in that dialog create worker thread:
BOOL MainHamsterDlg::OnInitDialog()
{
AfxBeginThread(WorkerThreadProc, m_hWnd, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
CDialogEx::OnInitDialog();
return TRUE;
}
the thread must exit dialog by sending return value IDCANCEL.
UINT WorkerThreadProc(LPVOID Param) //Sample function for using in AfxBeginThread
{
Sleep(1000); // process simulation
MainHamsterDlg * self = (MainHamsterDlg *)Param;
self->EndDialog(IDCANCEL);
return FALSE;
}
When compiling I do not get any error. when processing then getting on the point:
self->EndDialog(IDCANCEL);
error message:
Unhandled exception at 0x01503AD4 in L2Hamster.exe: 0xC0000005:
Access violation reading location 0x00000020.
that pointing my to dlgcore.cpp file:
void CDialog::EndDialog(int nResult)
{
ASSERT(::IsWindow(m_hWnd)); <<<<<===== to that line
m_bClosedByEndDialog = TRUE;
if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
EndModalLoop(nResult);
::EndDialog(m_hWnd, nResult);
}
I don't know what I'm doing wrong. any solution?
I assume you intended to pass a pointer to the dialog to the thread proc. But you passed null instead:
AfxBeginThread(WorkerThreadProc, NULL, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
Should be:
AfxBeginThread(WorkerThreadProc, this, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
You will also need to coordinate the end of the thread with the end of the dialog to ensure the dialog isn't dismissed before the thread ends. (I assume it is some sort of progress dialog).
This looks like it is the problem to me:
AfxBeginThread(WorkerThreadProc, NULL, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
followed by
UINT WorkerThreadProc(LPVOID Param) //Sample function for using in AfxBeginThread
{
MainHamsterDlg * self = (MainHamsterDlg *)Param;
self->EndDialog(IDCANCEL);
...
}
Here, Param is NULL, so self is NULL. You then dereference a null pointer.

DirectX program throw an exception when it is destroyed under window mode

The problem occurs when I try to play with one of the Rastertek DirectX 11 tutorials.
I changed the const bool fullscreen value to false so the program runs under window mode
I changed the window style from CLIPPINGWINDOW to OVERLAPPEDWINDOW
It works fine except that the program throws an exception when the window is destroyed:
Unhandled exception at 0x779715ee in FrustumCulling.exe: 0xC0000005: Access violation reading location 0xfeeeff5e.
it's tutorial 16 at http://www.rastertek.com/dx11tut16.html
The only modifications I made are:
In graphicsclass.h
const bool FULL_SCREEN = true //false;
and
SystemClass::InitializeWindows
{
...
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
WS_OVERLAPPEDWINDOW,
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
...
}
Is it possible you're still setting up your swapchain in fullscreen mode?
When I was running into this issue, adding this to my DxClass' destructor solved it
if(_swapChain != nullptr)
{
_swapChain->SetFullscreenState(false, NULL);
_swapChain->Release();
_swapChain = nullptr;
}
As per one of the Rastertek comments in one of the tutorials, the swapchain has to have the fullscreen set to false prior to being released.
When you set up your DXGI_SWAP_CHAIN_DESC assure you are using swapChainDesc.Windowed = !FULL_SCREEN and not a literal bool value, and make sure you set FULL_SCREEN to false, FULL_SCREEN = true //false; wouldn't do that and shouldn't compile.