Is this a bug?

82 views
Skip to first unread message

Niklas Rosenqvist

unread,
Oct 29, 2013, 3:19:20 PM10/29/13
to urh...@googlegroups.com
Hi! I've been studying the NinjaSnowWar sample to learn how the engine should be used. I was building my own project with bits and pieces from the different samples when I stumbled upon a null pointer exception. I found that this error was from a snippet I got from NinjaSnowWar and I was wondering if this is a bug or if I'm using the engine incorrectly.

It works when I run it from it's default location:

niklas@Dash:/opt/Urho3D/Bin$ ./Urho3D Data/Scripts/NinjaSnowWar.as

But when I run it from my project folder (in which I've copied all the resources into):

niklas@Dash:~/Workspace/ugame$ /opt/Urho3D/Bin/Urho3D NinjaSnowWar.as

...I get the following errors repeated on every frame:

[Tue Oct 29 20:12:24 2013] ERROR: NinjaSnowWar.as:1015,17 - Exception 'Null pointer access' in 'void UpdateControls()'
AngelScript callstack:
   
NinjaSnowWar.as:void UpdateControls():1015,17
   
NinjaSnowWar.as:void HandleUpdate(StringHash, VariantMap&inout):408,5

[Tue Oct 29 20:12:24 2013] ERROR: NinjaSnowWar.as:1137,13 - Exception 'Null pointer access' in 'void UpdateStatus()'
AngelScript callstack:
   
NinjaSnowWar.as:void UpdateStatus():1137,13
   
NinjaSnowWar.as:void HandlePostUpdate():445,5

These are the code snippets causing this:

// void UpdateControls():1015,17

Node@ playerNode = gameScene.GetChild("Player", true);
if (playerNode !is null)
{
    log
.Write("prenode");
   
Ninja@ playerNinja = cast<Ninja>(playerNode.scriptObject);
    playerNinja
.controls = playerControls;
    log
.Write("postnode");
}

// void UpdateStatus():1137,13

GameObject@ object = cast<GameObject>(playerNode.scriptObject);
health
= object.health;



There is absolutely no difference made to the files other than executing them in another directory relatively to the Urho3D executable. Is this an error caused by a misunderstanding of how the Urho3D script functionality works or is this an issue with Urho3D?

Thanks!

Lasse Öörni

unread,
Oct 29, 2013, 4:30:17 PM10/29/13
to urh...@googlegroups.com
When you invoke the engine the second way, it is still registering the CoreData & Data directories next to the executable as resource paths, and files from inside them will have precedence over the working directory. To only use the working directory as a resource directory you should invoke the engine in the following way (but now you will need also all the subdirectories from inside CoreData copied to your project directory)

Urho3D <scriptfilename> -p .


Now, to the cause of the exception: the objects "prefab" xml files that the game instantiates from the Data/Objects folder refer to the script file Scripts/NinjaSnowWar.as (which further #includes the actual object behavior script files)

The problem is that AngelScript defines the class hierarchy per script module, and now two modules end up being compiled:
- <working directory>/NinjaSnowWar.as
- <Urho executable directory>/Data/Scripts/NinjaSnowWar.as

The other module does not "see" the classes from the other, and when it tries to cast a script object eg. to the Ninja class it comes back as null, and therefore the exception. You'll need to change the prefab files to refer to your script file. Look for eg. the line

        <attribute name="Script File" value="ScriptFile;Scripts/NinjaSnowWar.as" />

and change it to

        <attribute name="Script File" value="ScriptFile;NinjaSnowWar.as" />


Niklas Rosenqvist

unread,
Oct 29, 2013, 6:37:01 PM10/29/13
to urh...@googlegroups.com
Thanks, I got it running now! Though I've found a couple of issues that might be worth reporting.

  1. The default Utilities/Network.as script parses (ParseNetworkParameters()) the value of -p as the server address since it selects it by index and not "getopts"-style. That made NinjaSnowWar.as try to connect to .:1234 instead of localhost:1234 (or whatever the default is).
  2. Instead of also adding the CoreData contents into my project I should be able to just specify another resource locations as the documentation suggests:

    -p<paths> Resource path(s) to use, separated by semicolons

    but if I test this by renaming the "Shaders" directory in my project to something else and instead specify:

    -p ".;/opt/Urho3D/Bin/CoreData"

    ...the program doesn't locate the shaders. Is the documentation wrong or should this be possible

Is this the preferred way of working with script based games? Is another project structure preferred?

Lasse Öörni

unread,
Oct 29, 2013, 7:31:03 PM10/29/13
to urh...@googlegroups.com
The Network.as script is bugged then, thanks for reporting!

The command line parsing is rather primitive, so there should be no space; instead use -p".;opt/Urho3D/Bin/CoreData"

Generally I would recommend working directly inside the Urho3D checkout, or copying the executable to where you are working. You might want to setup your own executable anyway which would eg. disable unwanted command line options.


Lasse Öörni

unread,
Oct 29, 2013, 7:34:25 PM10/29/13
to urh...@googlegroups.com
Actually, when you use the space-less form, the Network script should also work as expected.

Niklas Rosenqvist

unread,
Oct 30, 2013, 4:23:27 AM10/30/13
to urh...@googlegroups.com
But wouldn't that still be an issue if I were to use multiple command line parameters since it's parsing the arguments based on their index? I might want to specify other arguments such as -w or -x and -y, then it would still fail.

Lasse Öörni

unread,
Oct 30, 2013, 4:52:29 AM10/30/13
to urh...@googlegroups.com
All arguments with a number/string parameter are to be supplied without space, ie -x1024 -y768.

The script is counting arguments starting without - separately, while ignoring those starting with - . The first argument without - is the script file name, the second is the server address, the third the username (if connecting to a server). So if the code doesn't contain implementation bugs, it should already work.


Niklas Rosenqvist

unread,
Oct 30, 2013, 4:59:27 AM10/30/13
to urh...@googlegroups.com
Ah, I see, then I apologize for the trouble :) can that be made clearer in the documentation, perhaps? Since it's not how you usually supply parameter values (atleast in Linux), just showing an example would be enough.
Reply all
Reply to author
Forward
0 new messages