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

Started by
2 comments, last by Santharn 21 years, 7 months ago
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!
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.
Why make it simple when you can make it sooo nice and complicated?
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 macroCErrorProtocol::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]
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!)

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement