gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > st9bad_alloc

#98605 - yal - Wed Aug 16, 2006 11:00 am

Hi,
I got some weird problems using DevKitPro with libnds. I'm new to Ds programming, so hopefully I'm missing something obvious and you'll be able to help me :)

I have a class like that :

Code:


class CApp
{
   virtual void Init();
   ...
   Some other function here
   ...

   CBoard * m_pBoard;
};

class CNdsApp : public CApp
{
   ...
   Some Function here
   ...
   
   int x;
   int y;

   int         m_bPreviouslyTouching;

   unsigned short * m_pMap;   
   int         m_iBoardOffsetX; //Offset in tiles
   int         m_iBoardOffsetY; //Offset in tiles   
};

class CBoard
{
   ...
   some function
   ...

   struct SBox
   {
      EBoxContent Content;
      bool aNeighbors[4];
   };

   SBox m_Board[BOARD_SIZE_X][BOARD_SIZE_Y];   
};


CNdsApp is instantiate with a new in the main function of the Arm9 at application start-up, and the class CBoard is instantiate the same way in the Init function of CApp (called right after the new)
On run-time I got an exception that seem to happen on the second new (I only got 2 new in my application) : st9bad_alloc.

The weird thing is that the exception doesn't happen if I move my two first int of CNdsApp (x and y) at the bottom of the class (every other emplacement make the application crash). My first though was memory alignment problem, but my class contain only 32 bit, so I don't see how that could cause memory alignment issue.
I don't think it's because I run out of memory either since I allocate only those two little classes.

Any idea?

#98621 - yal - Wed Aug 16, 2006 3:34 pm

I did some further testing and the problem disappeared suddenly and I can't reproduce it anymore ...
I think a simple rebuild all would have fix my problems, I wish I had think about that before :)
Still weird tough...

#98639 - sajiimori - Wed Aug 16, 2006 6:48 pm

A code file probably got out-of-sync with a header, causing garbage to be passed to operator new. All things being equal, garbage unsigned int values tend to be big. :)

#98711 - jonezer4 - Thu Aug 17, 2006 12:53 am

I got this error while attempting a software reset (calling the swiSoftReset() function) in the arm9. Anyone know how to fix this?