Factory constructor crashes as creatables.push_back

Development of custom GMAT plugins

Factory constructor crashes as creatables.push_back

Postby davidf » Tue Jul 10, 2012 9:22 pm

I have the following code in the no-arg constructor of a my factory for a GMAT command that I'm trying to write.

Code: Select all
#define VERBOSE 1
#define INFO(STR) MessageInterface::ShowMessage(STR)
#define INFO1(STR, VAR1) MessageInterface::ShowMessage(STR,VAR1)
#define INFO(STR)
#define INFO(STR, VAR1)

JavaizeFactory::JavaizeFactory() : Factory(Gmat::COMMAND) {
   INFO("Entering JavaizeFactory no-arg constructor.\n");
   INFO1("creatables is empty?  Answer = %d\n", creatables.empty());
   if (creatables.empty()) {
      INFO("\tEntered pushback block.\n");
      INFO("\tLeaving pushback block.\n");
   INFO("Leaving JavaizeFactory no-arg constructor.\n");

This crashes GMAT. When I run through the console version (having defined DEBUG_PLUGIN_REGISTRATION in Moderator.cpp to get additional trace), the last message that I get is "Entered pushback block." and then some error messages from GMAT:
Unknown Error occurred during initialization

Moderator failed to initialize! Unable to run GmatConsole.

Sometimes I also get a Segmentation Fault message at the end, but this is not reproducible.

I'm at a loss for what's happening here. Has anyone seen such a thing before? I have not dug deeply into the parent class's constructor to see what it does to creatables before my constructor runs, but the line of the apparent crash is just a call to an STL method, and the call to empty already worked, so the variable is initialized. If I comment out the push_back line, GMAT runs all the way through initialization, although GMAT in that case reports no object types for this factory. I'm using MS Visual C++ on a 64-bit Windows machine. My configuration is Debug and Win32.
Posts: 6
Joined: Tue Jul 10, 2012 2:58 pm

Re: Factory constructor crashes as creatables.push_back

Postby davidf » Thu Jul 12, 2012 6:01 pm

I'm still trying to track down the problem. As I add or remove lines to the code, I get one of two types of errors:
    1. Segmentation fault
    2. bad_alloc exception thrown out of the push_back method

I've also seen strange behavior where I get past the push_back method, but the creatables vector still says that it has no elements without creating any errors.

It seems like some sort of memory access problem somewhere, so I'm now trying to run GMAT through the Visual C++ debugger. Unfortunately I cannot even get to the point where plugins are loaded. Instead I get an unhandled exception "Access violation" originating from somewhere in the STL during the call to GMAT_D.exe!GmatApp::OnInit (Line 142 of GmatApp.cpp in my version):
Code: Select all
theModerator = Moderator::Instance();

If I put a break point on this like, the crash occurs before the break point stops it.

I'm at a point where I'm unable to see what might be issues with my use of the debugger (I'm used to g++/gcc/gdb on linux, so maybe I'm misusing the MS tools), what's an issue with my code, and what's an issue with GMAT. Any advice would still be appreciated!

Posts: 6
Joined: Tue Jul 10, 2012 2:58 pm

Re: Factory constructor crashes as creatables.push_back

Postby davidf » Thu Jul 12, 2012 8:44 pm

I seem to have fixed my original problem and I suspect that the same issue was at play in the follow-on. Visual C++ doesn't allow "Debug" and "Release" code to mix when STL objects are passed between DLLs. There's some information about this at the link in case anyone later wants to read more about the issue.

Posts: 6
Joined: Tue Jul 10, 2012 2:58 pm

Re: Factory constructor crashes as creatables.push_back

Postby CodyMale » Fri Mar 13, 2020 6:09 am

Factory construction has some crashes that were available as some creatable on this it was compulsory to make some push backs on it. I will have to get admire services that have paper writing service review on it this was for getting better knowledge about the company.
Posts: 1
Joined: Fri Mar 13, 2020 6:09 am

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest