[omniORB] application attempted to invoke an operation on a nil reference

Robert Gunion rfgunion at lbl.gov
Wed Jun 30 08:00:56 BST 2010


Your reference to the server is going out of scope when initializePlugin finishes, so the pointer you've stored is meaningless.  That's what _var's are for.  For a full explanation see Henning and Vinoski's Advanced CORBA Programming with C++ (http://www.amazon.com/Advanced-CORBA-R-Programming-C/dp/0201379279).

You'll need something like this:

class calculator_Functions_i: public POA_calculator::Functions 
{
private:
	calculator::GuiManager_var pManager;
public:
	calculator_Functions_i();
	virtual ~calculator_Functions_i();

	void manager(calculator::GuiManager_ptr);
	calculator::GuiManager_ptr manager();
	void pi(const char* id);
	void initializePlugin(calculator::GuiManager_ptr manager);
};
...

void calculator_Functions_i::manager(calculator::GuiManager_ptr ptr)
{
	pManager = calculator::GuiManager::_duplicate(ptr);
}

calculator::GuiManager_ptr calculator_Functions_i::manager()
{
	return pManager._retn();
}

void calculator_Functions_i::pi(const char* id)
{
	calculator::GuiManager_var manager = calculator::GuiManager::_duplicate(manager());
	if (CORBA::is_nil(manager))
	{
		cerr << "manager is null" << endl;
	}
	else
	{
		cerr << "manager is not null" << endl;
		
		char* displayId = "display";
		char* text = "text";

		// You need a getText or similar method here
		//cerr << manager << endl;
		manager->setText(displayId, text);
	}
}

void calculator_Functions_i::initializePlugin(calculator::GuiManager_ptr manager)
{
	manager(manager);
	
	// load gui.xml:
	ifstream xmlFile;
	
	xmlFile.open ("gui.xml");
	if (xmlFile.is_open())
	{
		
		xmlFile.seekg(0, ios::end);
		unsigned long fileSize = streamoff(xmlFile.tellg())+1;
		xmlFile.seekg(0, ios::beg);
		
		char* pBuffer = new char[fileSize];
		
		xmlFile.read(pBuffer, fileSize-1);
		
		// terminate the string:
		pBuffer[xmlFile.gcount()] = '\0';
		
		xmlFile.close();
		
		manager->initializeUserInterface(pBuffer);
		
		char* displayId = "display";
		char* text = "text";
		
		manager->setText(displayId, text);
	}
}


On Jun 30, 2010, at 2:27 AM, Wittstruck, Nicholas wrote:

> Hi,
> 
> i am trying to connect a c++ program to a java server, using corba. 
> 
> The server finds my client, and is able to call the first operation (initializePlugin(...)). This method sets a guiManager, which is used to call some functions on the server.
> This works only in the first call to the c++ program. Whenever I try to access the guiManager afterwards in a second method (pi(...)), I get the following error:
> 
> ----
> omniORB: omniRemoteIdentity deleted.
> omniORB: ObjRef(IDL:calculator/GuiManager:1.0) -- deleted.
> omniORB: Return from remote call 'initializePlugin' to: root<0> (active)
> omniORB: inputMessage: from giop:tcp:[::ffff:192.168.0.102]:55666 111 bytes
> omniORB:
> 4749 4f50 0102 0000 0000 0063 0000 0006 GIOP.......c....
> 0300 0000 0000 0002 0000 000e fe23 722a .............#r*
> 4c00 0007 2c00 0000 0000 0001 0000 0003 L...,...........
> 7069 0074 0000 0003 0000 0011 0000 0002 pi.t............
> 0002 000c 0000 0001 0000 000c 0000 0000 ................
> 0001 0001 0001 0109 4e45 4f00 0000 0002 ........NEO.....
> 0014 0001 0001 0109 0000 0003 7069 00   ............pi.
> omniORB: Receive codeset service context and set TCS to (ISO-8859-1,UTF-16)
> omniORB: Dispatching remote call 'pi' to: root<0> (active)
> manager ist not null
> 006E1CC8
> omniORB: ERROR -- the application attempted to invoke an operation
> on a nil reference.
> omniORB: throw INV_OBJREF from exception.cc:487 (NO,INV_OBJREF_InvokeOnNilObjRef
> )
> omniORB: Scan for idle connections (1277850162,124000000)
> ----
> 
> I am kinda confused, because I am testing wether the manager is null or not, using CORBA::is_nil(). This method says, that the manager is not null, but the program keeps crashing when it accesses the manager to call the setText method. 
> The code of my c++ class is:
> 
> 
> ----
> class calculator_Functions_i: public POA_calculator::Functions 
> {
> private:
> 	calculator::GuiManager_ptr pManager;
> public:
> 	calculator_Functions_i();
> 	virtual ~calculator_Functions_i();
> 
> 	void manager(calculator::GuiManager_ptr);
> 	calculator::GuiManager_ptr manager();
> 	void pi(const char* id);
> 	void initializePlugin(calculator::GuiManager_ptr manager);
> };
> ...
> 
> void calculator_Functions_i::manager(calculator::GuiManager_ptr ptr)
> {
> 	pManager = ptr;
> }
> 
> calculator::GuiManager_ptr calculator_Functions_i::manager()
> {
> 	return pManager;
> }
> 
> void calculator_Functions_i::pi(const char* id)
> {
> 	if (CORBA::is_nil(calculator_Functions_i::manager()))
> 	{
> 		cerr << "manager is null" << endl;
> 	}
> 	else
> 	{
> 		cerr << "manager is not null" << endl;
> 		
> 		char* displayId = "display";
> 		char* text = "text";
> 
> 		calculator::GuiManager_ptr manager = calculator_Functions_i::manager();
> 		cerr << manager << endl;
> 		calculator_Functions_i::manager()->setText(displayId, text);
> 	}
> }
> 
> void calculator_Functions_i::initializePlugin(calculator::GuiManager_ptr manager)
> {
> 	calculator_Functions_i::manager(manager);
> 	
> 	// load gui.xml:
> 	ifstream xmlFile;
> 	
> 	xmlFile.open ("gui.xml");
> 	if (xmlFile.is_open())
> 	{
> 		
> 		xmlFile.seekg(0, ios::end);
> 		unsigned long fileSize = streamoff(xmlFile.tellg())+1;
> 		xmlFile.seekg(0, ios::beg);
> 		
> 		char* pBuffer = new char[fileSize];
> 		
> 		xmlFile.read(pBuffer, fileSize-1);
> 		
> 		// terminate the string:
> 		pBuffer[xmlFile.gcount()] = '\0';
> 		
> 		xmlFile.close();
> 		
> 		calculator_Functions_i::manager()->initializeUserInterface(pBuffer);
> 		
> 		char* displayId = "display";
> 		char* text = "text";
> 		
> 		calculator_Functions_i::manager()->setText(displayId, text);
> 	}
> }
> 
> ----
> 
> The server cann call initializePlugin(..), and everything works fine. Whenever the server tries to call pi(...) the error listed above comes up. Does anyone have an idea, what the problem might be? I'm using the newest omniORB version.
> 
> Thanks in advance,
> 
> Nicholas.
> 
> 
> 
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list




More information about the omniORB-list mailing list