Archived

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

Obolus

Silly class causes illegal operation! Please help!

Recommended Posts

Obolus    122
Hi everyone, Hopefully you can give me a hand with this problem... As soon as I create an instance of this one class in my program, it causes an illegal operation and bombs out to Windows (when the object is created and the app is full-screen, I don''t get an error message - it just quits). I recently implemented file logging so I could track errors like this, and I am able to discern that the program crashes at the point where the instance of the object is created. I put a log instruction into the constructor of the object, yet nothing appears in the log file (the logger opens and closes a file each time for high-precision, so I know the logger itself is working alright). Here''s the class definition, it''s a node structure for a linked list: // ------------------------- // FE_OBJECT_LL_NODE Class // ------------------------- class FE_OBJECT_LL_NODE { public: friend class FE_OBJECT_LL; // Is a friend of the FE_OBJECT_LL class. FE_OBJECT_LL_NODE( void ); // Default constructor. FE_OBJECT_LL_NODE( char *FileName ); // Parameterised constructor. ~FE_OBJECT_LL_NODE( void ) {} // Destructor. FE_OBJECT GetData( void ); // Return the node''s data. FE_OBJECT_LL_NODE *GetNext( void ); // Return the Next node. FE_OBJECT_LL_NODE *GetPrev( void ); // Return the Previous node. FE_OBJECT m_FEObject; // The node''s data. private: FE_OBJECT_LL_NODE *m_pNext; // The Next node in the list. FE_OBJECT_LL_NODE *m_pPrev; // The Previous node in the list. }; // ------------------------- The class isn''t finalised, as you can see because the data object (FE_OBJECT) is still public, yet I have a GetData() function. Anyway, when I create the node class first thing in my program for testing, I get the standard Windows error message "your program has caused an illegal operation blah blah blah". I click on "debug", and, interestingly, VC++ opens up the "d3dx8math.inl" file from the DX8 SDK. It points to the the line "x = pf[0];" in the following part of the file: //-------------------------- // 3D Vector //-------------------------- D3DXINLINE D3DXVECTOR3::D3DXVECTOR3( CONST FLOAT *pf ) { #ifdef D3DX_DEBUG if(!pf) return; #endif x = pf[0]; y = pf[1]; z = pf[2]; } I really don''t know what''s going on, so naturally I would appreciate any help that anyone can give me. Hope you can help! Cheers, Gareth

Share this post


Link to post
Share on other sites
Pactuul    122
Good lord man. Do I have to help you put two and two together (just messing with ya). For one thing it is obvious their is nothing wrong with your header file. it''s in the .cpp, because if your causing an error with directx matrix, then it''s with in the class constructor because you said it crashes when you make an instance of the object. So DO this:

Check in your constructor where your making a D3DXMATRIX and make sure your passing an pointer that is ACTUALLY been made. Because it''s obvious that in the line "x = pf[0];" pf is not initialized, but this should have been caught by the line above it

#ifdef D3DX_DEBUG
if(!pf)
return;
#endif

so this tells me you need to run the program in debug mode and it would catch this.

Mainly just make sure your passing a real pointer to D3DXMATRIX in your class constructor of FE_OBJECT_LL_NODE

Geez....

Pactuul


"The thing I like about friends in my classes is that they can''t access my private members directly."



Share this post


Link to post
Share on other sites
Obolus    122
Thanks Pactuul.

I know what you''re getting at, but nowhere in my class do I use a D3DXVECTOR3 structure, or any other D3DX structure for that matter - hence my confusion...

Here are the two constructors for my class, so that you can see what goes on when they are initialised:


// ---------------------------------------
// FE_OBJECT_LL_NODE Default Constructor
// ---------------------------------------
FE_OBJECT_LL_NODE::FE_OBJECT_LL_NODE()
{
ProgLog( "Constructing object." );

m_pNext = NULL;
m_pPrev = NULL;
}
// ---------------------------------------


// ---------------------------------------------
// FE_OBJECT_LL_NODE Paramaterised Constructor
// ---------------------------------------------
FE_OBJECT_LL_NODE::FE_OBJECT_LL_NODE( char *Filename ) :
m_FEObject( Filename )
{
ProgLog( "Constructing object from file." );

m_pNext = NULL;
m_pPrev = NULL;
}
// ---------------------------------------------


...And basically that''s it.

Theoretically, as soon as the object is created, a log entry should be made to the log file, but it isn''t.

Also, if, as I was thinking, the error might lie in one of the class'' member objects (like FE_OBJECT), the log entry would still be made because the constructor code would be executed before the member objects are constructed - am I correct in thinking this, or *could* it be a problem with a member object?

Thanks again,
Gareth

Share this post


Link to post
Share on other sites
cheda13    122
As far as I can see there is nothing wrong about your class and fact that there is no log information points that error has hapened before calling constructor and that would be when variables in your class are being initialised. So the problem must be in your FE_OBJECT class ( I thik that it is the name- something about data) . Its constructor is being called before constructor of the class you think is the problem and there is no debug info ''cause it''s in header.

I don''t now if you used D3DXVECTOR in FE_OBJECT class but if you did you found where is your problem REALLY.

Hope that helped...

Share this post


Link to post
Share on other sites
Qoy    127
I don''t know how you''ve determined that it''s happening in the constructor, but if it''s just the log file then you *may* have a problem.

Files are flushed when they''re closed by default, unless there''s a certain amount of data which will flush when it''s written.. but I don''t know about that.

You should try setting the file for immediate writing, if you haven''t already. The function for this from the C standard lib functions (the fopen series) is setvbuf(). Look it up for parameter info.

If you use that, then you''ll know for certain if it''s happening before your first log entry, because it''s probably that it was crashing before the log was closed, and hence before it was written, before.

Other than that I would agree with the other posters. The most common cause of "illegal operation" errors in my experience is an access violation, so always make sure you don''t dereference memory that hasn''t been allocated yet.

Share this post


Link to post
Share on other sites
Sandman    2210
quote:

Anyway, when I create the node class first thing in my program for testing, I get the standard Windows error message "your program has caused an illegal operation blah blah blah". I click on "debug", and, interestingly, VC++ opens up the "d3dx8math.inl" file from the DX8 SDK. It points to the the line "x = pf[0];" in the following part of the file:



Run it in the debugger, and when it dies, step up the call stack (there is a button for this on the debug toolbar) to see where it is getting called from. This should give you some clues as to what might be going wrong...

PS: for your error logging, make sure you flush (eg fflush()) the file buffer after every data item, otherwise as Qoy says above, you cant be sure that the data that youve got is up to date.

Share this post


Link to post
Share on other sites