Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Santharn

MS-DirectX-Framework: Globlal instances of Variables not possible?

This topic is 5760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I´m relating to the example text3d from microsoft, but i guess it is the same with all other sample applications that use the framework from microsoft. I want to create an instance of an own class in the main-cpp-file (its name is text3d.cpp), so the instance of my class is globally acessable from all other further (sub)classes - a global variable. I´m then always getting an assertion error when closing the app. A global int-Variable or something simple like that seems to work without a problem. My instance isnt dynamically created (no "new"-operator), but member variables in this class are! I do not understand the assertion-error here, but i think it has to do with memory-management (especially the "delete"-operator). When i´m always klicking on the button to ignore the assertion, the program seems to work without a problem. How can this strange behaviour intercepted? thanks for your time!

Share this post


Link to post
Share on other sites
Advertisement
Impossible to say without seeing the code but try to check if you are deleting an empty(already deleted) pointer. Also, make sure that everything you new is deleted.

Share this post


Link to post
Share on other sites
Sorry, i was wrong, this has nothing to do with the DirectX-Sample-Framework from MS but with my mistakes.

The error occures in this ".cpp"-File:

      
#include "CErrorProtocol.h"

#include "Windows.h"

#include "DXUtil.h" //contains SAFE_DELETE_ARRAY macro



CErrorProtocol::CErrorProtocol( char* Filename ) {
m_strFilename = new char[ strlen(Filename) ];
m_strFilename = Filename;
m_Protocol = fopen( m_strFilename,"w" );
}


CErrorProtocol::~CErrorProtocol() {
fclose( m_Protocol );

//-->IN THIS LINE OCCURES THE ERROR:---------------------

SAFE_DELETE_ARRAY( m_strFilename); //<--THE ERROR

}


void CErrorProtocol::SetError( char *String ) {
OutputDebugString( String );
OutputDebugString( "\n" );

fprintf(m_Protocol, String );
fprintf(m_Protocol, "\n" );
}

what is wrong with this?



[edited by - Santharn on September 13, 2002 1:30:42 AM]

Share this post


Link to post
Share on other sites
If m_strFilename is defines as char* you cannot
use "m_strFilename = Filename" to set m_strFilename to the new name. This way you will loose the original pointer, you acquired via new[], and later deleting some invalid memory adress.

Try memcpy( m_strFilename, Filename, strlen( Filename ) + 1 );

Regards,
Endurion

(or even better: use std::string!)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!