Closed JaXt0r closed 1 year ago
Hi @JaXt0r, in this case, npcRef
in your implementation of TA_MIN
is nullptr
. This happens, because the value passed as the first parameter is actually SELF
which you did not set when calling the daily routine. You need to vm.global_self()->set_instance(tempNpc)
before calling the daily routine. You should also save the previous value of global_self
and restore it after you have called the daily routine.
Here's the steps you can take to debug a problem like this. In the offending callback, put a vm.print_stack_trace()
(or call it from a debugger). This will give you a call stack as well as the values currently on the VM's stack:
------- CALL STACK (MOST RECENT CALL FIRST) -------
in TA_MIN at 0x60a4c
in TA_STAND_WP at 0x60a4c
in RTN_START_309 at 0x9bc7d
in WLD_INSERTNPC at 0x220238
in STARTUP_NEWWORLD_PART_CITY_01 at 0x220238
in STARTUP_NEWWORLD at 0x224d7a
------- STACK (MOST RECENT PUSH FIRST) -------
Here we can see that TA_MIN
is called from TA_STAND_WP
which we can look up either in the script source which can be obtained from the Gothic II Modkit (_work/Data/Scripts/CONTENT
) or by using the zscript
tool from phoenix-studio. Here's how you could use it in this case:
$ zscript -f GOTHIC.DAT -k -s TA_STAND_WP
func void TA_STAND_WP(var int START_H, var int START_M, var int STOP_H, var int STOP_M, var string WAYPOINT) {
TA_MIN(SELF, START_H, START_M, STOP_H, STOP_M, 9784, WAYPOINT);
}
Here you can see that TA_MIN
is called with SELF
as the first parameter.
Wonderful. Works! Saved my day. :-)
Also thanks for the detailled explanation. Especially the stacktrace is super easy to use.
Hi there,
I'm currently struggling with shared_ptr on an external function call. If I want to check values of the npcRef smart pointer, I get a Segmentation fault. I checked with OpenGothic's implementation but can't find my issue why I get the error.
Any pointer into the right direction would be helpful. :-) Thank you.
Output: