Hello, we are the guys who are making a python game. Remember us?
We are currently stuck on a bit of an annoying bug:
somewhere in our code, we do this:
to make python output things to out console, which is a high-level graphical thing, to make our game seem more hacky and cool. (parser means PythonInterpreter, we just ended up with that name for some reason)
This works fine for python code executed with parser.exec(), but not so much when this module (which implements a java interface) is run:
from org.ntnu.pythia.game.behaviour import Behaviour
def react(self, event):
print "testbehaviour received event:"
If we comment out the line where we change the output for the parser, this also works like a charm. It's these two things in combination, however, that gives us the problem. It seems like 'print' makes a NullpointerException. We don't quite know how to debug this, and we're mostly guessing at the inner workings of print, but it seems like most likely, the thing that's null is either the outputstream (since that's the only thing we've changed), or one of the objects the Outputstream needs to do the write() function. In the debugger we can see that there is in fact an OutputStream present, and besides, it works fine in the case of parser.exec("print 'something'") as mentioned.
This could be a bug in Jython, but we are in way over our heads as far as complexity goes, so we are not going to claim that we haven't made some kind of mistake.
self is not null
event is not null
commenting out the lines with print on them makes the exception go away (as does not setting the Out for the parser)
with our debugging capability we have managed to find out that the nullpointer is somewhere within the call on line 165 in PyTableCode:
ret = funcs.call_function(func_id, frame, ts);
and that's where our trace ends. There's no shortage of variables visible in that scope that are null, and we don't know what most of them are anyway. And we don't know how jython really works.. I did see a variable that said 'react' at some point so I guess that means it is inside that method.
The setOut() method requires an outputStream, but is it possible that somewhere in jython, there is something that expects the outputStream to be a Python File, and calls a method we haven't implemented? And that this somehow doesn't happen in the case of parser.exec()?
If anyone can shed any light on what our mistake is at all, we could use any help we can get. Otherwise we might just have to use separate interpreters. I think they can share the same "variable space", can't they? wait.. wouldn't the outputstream be one of such variables? .. oh dear..
But more likely, if anyone can suggest a workaround for this problem, we would listen to that aswell.
- We need help! - Andreas