Crash when talking to NPC

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Crash when talking to NPC

Post by Karlos »

First, is this forum the best place for Studio/usecode-related questions, or should I join the mailing list? The reason I ask is that I'll likely have a lot of questions and problems on the way, and I don't know if this will clutter the forum too much. :-)

Anyway, I've gotten as far as writing a NPC and writing usecode for him. I've just done a barebones function for now, that I'll expand on once I get it working. The code compiles fine, but Exult segfaults when I try to initiate a conversation with him (event == 1). The function gets run and exits normally on an event of 0, however.

Here's the message I get:

Running usecode 0401 () with event 1
Segmentation fault

I believe it is crashing on the "say( "Hello..." );" line, but I don't know why. Any ideas?

The usecode function I wrote appears below.



-Karl

---

Narrator 0x401 ()
{
if( event == 0 )
{
// no-op for now
return;
}
else if( event != 1)
return;
UI_show_npc_face( item );
say( "Hello..." );
UI_add_answer( "Bye" );
converse
{
if( response == "Bye" )
break;
}
UI_remove_npc_face( item );
}
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by drcode »

Just a guess: It's crashing because you don't have a 'fonts.vga' file yet. We ought to have a basic one included in EStudio, but I haven't done it yet. Maybe that will be my next task.

What you'll really want to do is to build Exult for debugging (one of the configure options), and run it with gdb. Then you'll know exactly where it's crashing.
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by Karlos »

No, I recently copied that file from SI, too, and I know it's working, since I now see the "Map Editor Mode Enabled" and "Map Editor Mode Disabled" messages that I didn't before. I was planning on creating my own fonts.vga and pointers.shp files soon, so I can contribute these when I've finished them for inclusion with Exult if you like them.

Anyway, I had already run exult through gdb, but the information I got didn't help me figure out what was wrong. In case it helps, the crash seems to happen in vgafile.h at line 179:

Running usecode 0401 () with event 1

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 592)]
0x080d082c in ShapeID::cache_shape() (this=0xbffff170) at shapes/vgafile.h:179

Here are a few lines of code leading-up to line 179 in vgafile.h (with the last line being 179):

void write(std::ostream& out); // Write out.
Shape_frame *get(DataSource* shapes, int shnum, int frnum,
DataSource *shapes2 = 0, int count1 = -1, int count2 = -1)
{


Thanks,

-Karl
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by drcode »

I'm afraid I can't tell anything. You might want to look up the stack ("up").

Meanwhile, I'll try something similar when I get a chance in the next day or two.
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by wjp »

If you have a debug build, you can also enable usecode tracing in your exult.cfg file:


..... (game specific, audio, graphics config stuff)


yes
verbose





This will allow you to see exactly what it's doing while executing usecode.
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by wjp »

Also, could it be the NPC doesn't have a face associated to it?
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by Karlos »

The NPC does have a face associated with it; I'm using the BG faces.vga for now, so when I created an NPC it automatically used Iolo's face for NPC #1. Here's the verbose usecode tracing output; does anything look to be unusual about it?


-Karl

--

Running usecode 0401 () with event 1
0000: push eventid
0001: pushi 0000H ; 0
0004: cmpeq
0005: jne 000C (jump taken)
000C: push eventid
000D: pushi 0001H ; 1
0010: cmpne
0011: jne 0015 (jump taken)
0015: push itemref
0016: calli _show_npc_face@1 ; 0003
[0x03]: show_npc_face(082e2858) = 0000
001A: addsi L0000 ; Hello...
001D: say
001E: pushs L0009 ; Bye
0021: calli _add_answer@1 ; 0005
[0x05]: add_answer("Bye") = 0000
0025: startconv 0036
Segmentation fault
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by Karlos »

Okay, I've attempted to do more debugging with gdb, but my lack of understanding of C++ and the Exult source prevented me from being very successful. I will mention the odd-seeming thing I did discover in case it will save time in identifying and fixing the problem.

When stepping through conversation.cc, function Conversation::show_avatar_choices(int num_choices, char **choices), the code goes this if-then-else sequence:

if (SI && (main_actor->get_flag(Obj_flags::petra) || (main_actor->get_skin_color() == 3 && main_actor->get_type_flag(Actor::tf_sex)))) // Petra
.
.
.
else if (SI && main_actor->get_skin_color() == 3) // Automaton
.
.
.
else if (SI)
.
.
.
else

Here it skips the first 3 and goes to the last else. Not suprizing since we're not running SI here. After this, we get to:

// BG Multiracial Hack
if (main_actor->get_skin_color() >= 0 && main_actor->get_skin_color() <= 2)

I have the white male avatar, but the comment makes this seem like it's meant for those playing a multiracial avatar in BG. It does go into this if block, then crashes shortly thereafter in vgafile.h, ShapeID::cache_shape.


-Karl
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by drcode »

I bet it's trying to get one of the shapes for a different race or gender, and not finding it. ShapeID::cache_shape() needs to check for shape #'s out of range and report an error (and probably quit). I'll look at that tonight. Currently, it crashes if the shape # being requested is out of range.

Last night, I did find a bug in the compiler, in that it's only passing one paramater to 'show_npc_face', when it should pass two. I didn't get the chance to check in the fix yet. It's probably not the cause of the crash, though, since the 2nd parameter will (for now) always be 0.
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by wjp »

Try changing

if (main_actor->get_skin_color() >= 0 && main_actor->get_skin_color() get_skin_color() >= 0 && main_actor->get_skin_color() <= 2 && GAME_BG)


-Willem Jan
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by Karlos »

Woo-hoo, that fixed it! Thanks.


-Karl
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by drcode »

Along with a bug-fix, there's a new feature in UCC: It now keeps track of function #'s. It should print an error if you use the same # twice, and it will automatically assign #'s sequentially, like the following:

fun1 0x600 () { }
fun2 () { } // Gets assigned 0x601.
fun3 () { } // Gets assigned 0x602.

While you might not want to use this for shape #'s or NPC's, it would be handy for eggs and subroutines where you don't care what numbers are assigned.

Let us know of any ideas you have for improving the language.
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Crash when talking to NPC

Post by Karlos »

Okay, thanks. I'm sure I'll have feedback as I get farther along in my project.


-Karl
Locked