Discussion:
[omniORB] application attempted to invoke an operation on a nil reference
Wittstruck, Nicholas
2010-06-30 15:27:51 UTC
Permalink
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.
Robert Gunion
2010-06-30 20:01:30 UTC
Permalink
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);
}
}
Post by Wittstruck, Nicholas
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.
----
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
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.
----
class calculator_Functions_i: public POA_calculator::Functions
{
calculator::GuiManager_ptr pManager;
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);
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);
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
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Urban Purkat
2010-06-30 20:54:09 UTC
Permalink
Hi,

I noticed that there is no vs10 package for omniORB 4.1.4 on
http://sourceforge.net/projects/omniorb/files/

Is there any plan to prepare it or do I need to build it myself?

TIA,
Urban
Duncan Grisby
2010-07-01 22:01:08 UTC
Permalink
Post by Urban Purkat
I noticed that there is no vs10 package for omniORB 4.1.4 on
http://sourceforge.net/projects/omniorb/files/
Is there any plan to prepare it or do I need to build it myself?
You should build it yourself.

When omniORB 4.1.5 is released, I will most likely build a version with
VS 2010.

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Wittstruck, Nicholas
2010-06-30 21:33:11 UTC
Permalink
Hi,

thank you for your replies. I was able to fix the issue with your help, you we're right. I get another error now - regardless wether I do anything in the pi method or not, the application crashes after its exceution. I've added my IDL file. Do you know why this happens?

Thank you btw for the book recommendation :) Ordered it right now.


----
omniORB: Receive codeset service context and set TCS to (ISO-8859-1,UTF-16)
omniORB: Dispatching remote call 'pi' to: root<0> (active)
manager is not null
00491CC8
omniORB: Invoke 'setText' on remote: key<.........t..................RootPOA....
..........>
omniORB: sendChunk: to giop:tcp:192.168.0.102:58808 117 bytes
omniORB:
4749 4f50 0102 0100 6900 0000 0800 0000 GIOP....i.......
0300 0000 0000 0000 3100 0000 afab cb00 ........1.......
0000 0020 8974 e70d 0000 0001 0000 0000 ... .t..........
0000 0001 0000 0008 526f 6f74 504f 4100 ........RootPOA.
0000 0008 0000 0001 0000 0000 1420 3030 ............. 00
0800 0000 7365 7454 6578 7400 0000 0000 ....setText.....
0800 0000 6469 7370 6c61 7900 0500 0000 ....display.....
7465 7874 00 text.
omniORB: inputMessage: from giop:tcp:192.168.0.102:58808 34 bytes
omniORB:
4749 4f50 0102 0001 0000 0016 0000 0008 GIOP............
0000 0000 0000 0001 4e45 4f00 0000 0002 ........NEO.....
0014 ..
omniORB: Return 'setText' on remote: key<.........t..................RootPOA....
..........>
omniORB: sendChunk: to giop:tcp:[::ffff:192.168.0.102]:58811 24 bytes
omniORB:
4749 4f50 0102 0101 0c00 0000 0600 0000 GIOP............
0000 0000 0000 0000 ........
----

idl files:

----
#include "gui.idl"
module calculator
{
interface Functions : Plugin
{
attribute GuiManager manager;
void pi(in string id);
};
};

module calculator
{
interface GuiManager
{
exception NotSupportedForType
{
string reason;
};

exception ElementNotFoundException
{
string reason;
};


void initializeUserInterface(in string xml);
void insertIntoUserInterface(in string xml, in string id);
void updateUserInterface(in string xml);

void setText(in string id, in string text) raises(NotSupportedForType, ElementNotFoundException);
string getText(in string id) raises(NotSupportedForType, ElementNotFoundException);
};


interface Plugin
{
void initializePlugin(in GuiManager manager);
};
};

----
Thomas Lockhart
2010-07-01 02:00:02 UTC
Permalink
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20100630/1be604a9/attachment.htm
Wittstruck, Nicholas
2010-07-01 02:15:32 UTC
Permalink
My original entry was: http://www.omniorb-support.com/pipermail/omniorb-list/2010-June/030659.html
I don't know how I messed that up ;)

Yes, the pi(in string id) method is called. The output gets printed, and code within will be executed. But when the execution finishes the program crashes. I'm not using JacORB, I'm using the Sun Orb.

This is just a wild guess, but since I'm not very familiar with the omniORB or C++, this info might help: I removed the String parameter from the pi(in string id) method, changing the idl to:

----
module calculator
{
interface Functions : Plugin
{
attribute GuiManager manager;
void pi();
};
};

----

Without the parameter my code does not crash. But I really can't understand why the code crashes after execution of the method, and furthermore, why removing a parameter helps?!
Does this user: http://www.omniorb-support.com/pipermail/omniorb-list/2002-November/022368.html has the same problem?
Though it seems as if he couldn't figure out a solution as well.


Nicholas
... I get another error now - regardless wether I
do anything in the pi method or not, the application crashes after
its exceution. I've added my IDL file. Do you know why this
happens?
I've already lost the original email with your code snippets so this is just speculation:

If you are changing your interface definitions make sure that your Java and C++ code have been compiled with the same version of IDL.

If you are really getting the pi() method in your C++ object then you probably have a reference problem. btw, you did not mention which Java ORB you are using. JacORB, right? The ORB delivered with Sun's jre is deficient in some features (or at least was in the past).
Thank you btw for the book recommendation :) Ordered it right now.
An aside (sort of): the book will recommend against using attributes in IDL. This is the best book I've run across for CORBA (nothing else is close) partly because it does make suggestions and recommendations on what to do or what to use in the standard and what to leave alone.

hth

- Tom


----
omniORB: Receive codeset service context and set TCS to (ISO-8859-1,UTF-16)
omniORB: Dispatching remote call 'pi' to: root<0> (active)
manager is not null
00491CC8
omniORB: Invoke 'setText' on remote: key<.........t..................RootPO=
A....
..........>
omniORB: sendChunk: to giop:tcp:192.168.0.102:58808 117 bytes
omniORB:
4749 4f50 0102 0100 6900 0000 0800 0000 GIOP....i.......
0300 0000 0000 0000 3100 0000 afab cb00 ........1.......
0000 0020 8974 e70d 0000 0001 0000 0000 ... .t..........
0000 0001 0000 0008 526f 6f74 504f 4100 ........RootPOA.
0000 0008 0000 0001 0000 0000 1420 3030 ............. 00
0800 0000 7365 7454 6578 7400 0000 0000 ....setText.....
0800 0000 6469 7370 6c61 7900 0500 0000 ....display.....
7465 7874 00 text.
omniORB: inputMessage: from giop:tcp:192.168.0.102:58808 34 bytes
omniORB:
4749 4f50 0102 0001 0000 0016 0000 0008 GIOP............
0000 0000 0000 0001 4e45 4f00 0000 0002 ........NEO.....
0014 ..
omniORB: Return 'setText' on remote: key<.........t..................RootPO=
A....
..........>
omniORB: sendChunk: to giop:tcp:[::ffff:192.168.0.102]:58811 24 bytes
omniORB:
4749 4f50 0102 0101 0c00 0000 0600 0000 GIOP............
0000 0000 0000 0000 ........
----

idl files:

----=20
#include "gui.idl"
module calculator
{
interface Functions : Plugin
{
attribute GuiManager manager;
void pi(in string id);
};
};

module calculator
{
interface GuiManager
{
exception NotSupportedForType
{
string reason;
};

exception ElementNotFoundException
{
string reason;
};


void initializeUserInterface(in string xml);
void insertIntoUserInterface(in string xml, in string id);
void updateUserInterface(in string xml);

void setText(in string id, in string text) raises(NotSupportedForTy=
pe, ElementNotFoundException);
string getText(in string id) raises(NotSupportedForType, ElementNot=
FoundException);
};


interface Plugin
{
void initializePlugin(in GuiManager manager);
};
};

---- =
Duncan Grisby
2010-07-01 22:04:48 UTC
Permalink
Post by Wittstruck, Nicholas
Yes, the pi(in string id) method is called. The output gets printed,
and code within will be executed. But when the execution finishes the
program crashes. I'm not using JacORB, I'm using the Sun Orb.
No doubt you are using Windows, and you are mixing debug and non-debug
code. Make sure you match all the debugging settings.

http://www.omniorb-support.com/omniwiki/FrequentlyAskedQuestions#head-9d43363054ee434faa49ca43c21026f09076aeec

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Wittstruck, Nicholas
2010-07-02 01:12:53 UTC
Permalink
I'm using the dir.mak from the echo example. Do I have to do any further changes? I tried to set up Visual Studio 2008 to run it, but I couldn't even start my application after compiling it. That is why I used the make file from the examples.

My make file looks like this:

----
#
# Usage:
# nmake /f dir.mak [<build option>]
#
# <build option>:
# all - build all executables
# clean - delete all executables and obj files
# veryclean - clean plus delete all stub files generated by omniidl
#
#
# Pre-requisite:
#
# Make sure that you have environment variable LIB and INCLUDE setup for
# using Developer studio from the command line. Usually, this is accomplished
# by source the vcvars32.bat file.
#

# Where is the top of this distribution. All executable, library and include
# directories are relative to this variable.
#
TOP = "..\omniORB-4.1.4"


##########################################################################
# Essential flags to use omniORB.
#
DIR_CPPFLAGS = -I. -I$(TOP)\include
#
# omniDynamic4_rt.lib is the runtime DLL to support the CORBA dynamic
# interfaces, such as Anys, typecodes, DSI and DII. In these examples, the
# runtime library is not required as none of these features are used.
# However, a bug in MSVC++ causes it to generate a bunch of references
# to functions in omniDynamic4_rt.lib when compiling the stubs.
# So now we link the dynamic library as well.
# An alternative is to replace the dynamic library with the much smaller
# library msvcstub.lib. The smaller library contains nothing but stubs
# for the required functions. This is enough when none of the dynamic
# interfaces are used. We use the small library here. If you prefer
# to link with the dynamic library, swap the comment on the next 2
# lines.
#OMNI_DYNAMIC_LIB = omniDynamic4_rt.lib
OMNI_DYNAMIC_LIB = msvcstub.lib -NODEFAULTLIB:libcmt.lib -NODEFAULTLIB:libcmtd.lib


CORBA_CPPFLAGS = -D__WIN32__ -D_WIN32_WINNT=0x0400 -D__x86__ -D__NT__ \
-D__OSVERSION__=4
CORBA_LIB = omniORB4_rt.lib omnithread_rt.lib \
$(OMNI_DYNAMIC_LIB) \
ws2_32.lib mswsock.lib advapi32.lib \
-libpath:$(TOP)\lib\x86_win32

CXXFLAGS = -O2 -MD -GX $(CORBA_CPPFLAGS) $(DIR_CPPFLAGS)
CXXLINKOPTIONS =

.SUFFIXES: .cc
.cc.obj:
cl /nologo /c $(CXXFLAGS) /Tp$<

########################################################################
# To build debug executables
# Replace the above with the following:
#
#OMNI_DYNAMIC_LIB = omniDynamic4_rtd.lib
#OMNI_DYNAMIC_LIB = msvcstubd.lib -NODEFAULTLIB:libcmt.lib -NODEFAULTLIB:libcmtd.lib
#CORBA_CPPFLAGS = -D__WIN32__ -D_WIN32_WINNT=0x0400 -D__x86__ -D__NT__ -D__OSVERSION__=4
#CORBA_LIB = omniORB4_rtd.lib omnithread_rtd.lib \
# $(OMNI_DYNAMIC_LIB) \
# ws2_32.lib mswsock.lib advapi32.lib -libpath:$(TOP)\lib\x86_win32
#CXXFLAGS = -MDd -EHsc -Z7 -Od $(CORBA_CPPFLAGS) $(DIR_CPPFLAGS)
#CXXLINKOPTIONS = -debug -PDB:NONE

all:: functions.exe

functions.exe: guiSK.obj functionsSK.obj functions.obj
link -nologo $(CXXLINKOPTIONS) -out:$@ $** $(CORBA_LIB)
clean::
-del *.obj
-del *.exe


veryclean::
-del *.obj
-del echoSK.* echo.hh
-del *.exe

gui.hh guiSK.cc: gui.idl
$(TOP)\bin\x86_win32\omniidl -T -bcxx -Wbh=.hh -Wbs=SK.cc -Wbtp gui.idl

functions.hh functionsSK.cc: functions.idl
$(TOP)\bin\x86_win32\omniidl -T -bcxx -Wbexample -Wbh=.hh -Wbs=SK.cc -Wbtp
functions.idl
Post by Duncan Grisby
Post by Wittstruck, Nicholas
Yes, the pi(in string id) method is called. The output gets printed,
and code within will be executed. But when the execution finishes the
program crashes. I'm not using JacORB, I'm using the Sun Orb.
No doubt you are using Windows, and you are mixing debug and non-debug
code. Make sure you match all the debugging settings.
http://www.omniorb-support.com/omniwiki/FrequentlyAskedQuestions#head-9d43363054ee434faa49ca43c21026f09076aeec
Duncan.
--
-- Duncan Grisby --
-- http://www.grisby.org --
Wittstruck, Nicholas
2010-07-02 01:39:21 UTC
Permalink
Thank you very much, I confused VS 2008 with vs8.. Didn't know that the internal number of VS 2008 is 9 and not 8, so I downloaded the wrong files. Thank you for this great support :)
Post by Duncan Grisby
Post by Wittstruck, Nicholas
Yes, the pi(in string id) method is called. The output gets printed,
and code within will be executed. But when the execution finishes the
program crashes. I'm not using JacORB, I'm using the Sun Orb.
No doubt you are using Windows, and you are mixing debug and non-debug
code. Make sure you match all the debugging settings.
http://www.omniorb-support.com/omniwiki/FrequentlyAskedQuestions#head-9d43363054ee434faa49ca43c21026f09076aeec
Duncan.
--
-- Duncan Grisby --
-- http://www.grisby.org --
Loading...