Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ access violation when calling instance method
    text
    copied!<p>I'm creating a DirectX 11 helper class that looks kind of like this:</p> <pre><code>#import "DXClass.h" // I have declared the constructor and the other methods here // All of the DirectX libraries are imported in the header as well DXClass::DXClass() { // Pointers created, etc. } DXClass:~DXClass() { // Other DirectX objects released // With an if (bbSRView) {}, the exception still occurs, so bbSRView is not NULL // bbSRView is a ID3D11ShaderResourceView* // When the other violation does not occur, one does here: bbSRView-&gt;Release(); bbSRView = NULL; // More releases void DXClass::Initialize() { SetupDisplay(); // Other initialization that works fine } void DXClass::SetupDisplay() { // This is where the debugger shows the access violation. // factory is declared as DXGIFactory* HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&amp;factory); // Loop through adapters and outputs, etc. } </code></pre> <p>This class is initialized like this: <code>dxClass = new DXClass();</code> The <code>Initialize()</code> function is called in another method of the class that created <code>dxClass</code>.</p> <p>When the application is run, I get an access violation at the beginning of the <code>setupDisplay()</code> function. However, if I take the code in <code>setupDisplay()</code> and put it in <code>Initialize()</code>, removing the call to <code>setupDisplay()</code>, no access violation occurs. Also, if I remove the code from <code>setupDisplay()</code> so that it is an empty function, and then call it in <code>Initialize()</code>, no access violation occurs.</p> <p>It appears that no pointers are NULL, and the application will start fine if it is changed as described above. However, on another note, the application receives another access violation when quitting. The debugger points to a <code>Release()</code> call on an <code>ID3D11ShaderResourceView*</code>, which I have pointed out in my code snippet. This pointer also appears to be valid.</p> <p>I have also checked the similar questions, but the <code>this</code> pointer of the class appears to be valid, and I am not creating any buffers that could be overflowing. There also isn't anything that could be deleting/freeing the object early.</p> <p>I have no idea what could be causing the errors. :/</p> <p>Thanks :D</p> <p>EDIT: Here's an isolated test, with the same errors: I have in my main function:</p> <pre><code>INT APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, INT) { App *app = new App(); app-&gt;Run(); app-&gt;Release(); } </code></pre> <p>In my <code>App</code> class, I have removed all window functionality and any other variables so that it looks like this:</p> <pre><code>App::App() { dxClass = new DXClass(); } App::~App() { delete dxClass; } void App::Run() { dxClass-&gt;Initialize(); while (true) {} // Never reaches here } </code></pre> <p>The access violation still occurs at the same place. Also, same results if I replace the factory instance variable with:</p> <pre><code>IDXGIFactory *f; HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&amp;f); </code></pre> <p>Which has worked for me in other applications.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload