IMPLEMENT_DYNAMIC_CLASS() twice

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
umesher
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Aug 17, 2005 8:24 am

IMPLEMENT_DYNAMIC_CLASS() twice

Post by umesher » Sat Aug 20, 2005 8:15 am

I get the following Error while running my application.

./src/common/object.cpp(237): assert "++nClass < nMaxClasses" failed: an infinite loop detected - have you used IMPLEMENT_DYNAMIC_CLASS() twice (may be by linking some object module(s) twice)? [in child thread]
Trace/BPT trap



I dont understand what linking obj module twice means......how does one end up linking two obj modules.... Is there anyway I can debug this.

Thanks for your help.

Umesh

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sat Aug 20, 2005 8:20 am

By showing some code, people can see what you done wrong. Please code the snippet and where it is used.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

umesher
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Aug 17, 2005 8:24 am

Post by umesher » Sat Aug 20, 2005 9:55 am

Extremely sorry about the not putting the code..
It is part of a very big project. I will try to isolate the wx part and send it.

Basically I am trying to create a console application. I am implementing APIs wrapped on top of wxwindows.
I am calling wxEntry from a seperate function which is part of a class and not main(). Do you think this is a problem?
the class

Code: Select all

Class BApp: public wxApp
{
      public: 
             OnInit ();
}
..
..
..
BApp::OnInit ()
{
 BasicFrame* fram = new BasicFrame ....
....
}

class BasicFrame: public wxFrame
{
....
....
.....
DECLARE_DYNAMIC_APP(BasicFrame)
};

IMPLEMENT_DYNAMIC_APP(BasicFrame, wxFrame)

BasicFrame:BasicFrame(.......)
{
..
...
}

class A {

void init ();

};

void A::init ()
{
 int argc = 1;
 char* argv[1] ;
argv[0] = "temp";
 wxEntry(argc, argv);
}


void main() {

A *a = new A;
a->init();
return ();
}

I hope this makes some sense. If it doesnt I can explain further.

Thanks a lot
Umesh

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sat Aug 20, 2005 10:02 am

The first question I would have for you is did you properly encapsulate the class definition in an IFDEF and in a header file so that it is not included more then once?

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

umesher
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Aug 17, 2005 8:24 am

Post by umesher » Sat Aug 20, 2005 10:16 am

Thanks for your response
Yes.....all my header files have a #ifndef header_file.h .......

Is there any debugging technique I can use to trace the no. of definitions.

Besides if a class is defined twice wouldnt the linker error out?

Do I have to make my implementation class (class A) a singleton......do you think that will solve the problem?

Thanks
Umesh

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Sat Aug 20, 2005 10:53 am

This is strange.

Are you sure the

Code: Select all

IMPLEMENT_DYNAMIC_APP(BasicFrame, wxFrame) 
line resides in the implementation (.cpp) file and not in a header file?

Edit: of course I meant IMPLEMENT_DYNAMIC_CLASS
Last edited by ssigala on Sat Aug 20, 2005 1:08 pm, edited 1 time in total.
Sandro Sigala - Kynosoft, Brescia

umesher
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Aug 17, 2005 8:24 am

Post by umesher » Sat Aug 20, 2005 11:08 am

yes.......I checked again .....the DECLARE_DYNAMIC_CLASS is in header file and IMPLEMENT_DYNAMIC_CLASS is in .cpp file.

Infact I put the header files into the .cpp file and complied. Still same error.

Is there some checks I can perform in the program to ensure correctness?

Thanks
Umesh

SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am
Contact:

Post by SnakeChomp » Sun Aug 21, 2005 2:31 am

umesher wrote:yes.......I checked again .....the DECLARE_DYNAMIC_CLASS is in header file and IMPLEMENT_DYNAMIC_CLASS is in .cpp file.

Infact I put the header files into the .cpp file and complied. Still same error.

Is there some checks I can perform in the program to ensure correctness?

Thanks
Umesh

Code: Select all

DECLARE_DYNAMIC_APP(BasicFrame)
};

IMPLEMENT_DYNAMIC_APP(BasicFrame, wxFrame) 
Are you using DECLARE_DYNAMIC_APP or DECLARE_DYNAMIC_CLASS? You claim that *_CLASS things are in the header / cpp, but in the code you provided *_APP is clearly used. This code is also clearly not the code you actually use. We cannot help you if you do not provide the code you physically use unless you post a real testcase. Testcases are code which compiles and runs and demonstrates your problem.

umesher
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Aug 17, 2005 8:24 am

Post by umesher » Sun Aug 21, 2005 9:05 am

again sorry....the wx part of the code is intergrated into other non - wx code. The whole thing is very big and I cannot post it here. Anyways I will try to simulate the same condition in a smaller program and try to post it.

Thanks,
Umesh

Post Reply