ID:2892173
 
Resolved
Byondapi: Byond_New() double-decref'd its arguments, resulting in runtime errors.
BYOND Version:515.1614
Operating System:Windows 11 Pro 64-bit
Web Browser:Firefox 118.0
Applies to:Dream Daemon
Status: Resolved (515.1617)

This issue has been resolved.
Descriptive Problem Summary:
Whenever passing text arguments to an object initializer (/New) via Byond_New, it seems it will corrupt input args (only tried with text, though) - the corruption seems to be related to the previous operation?

Numbered Steps to Reproduce Problem:
See code below, includes both a minimal reproducible C++ example, and the DM code to demonstrate the issue

Code Snippet (if applicable) to Reproduce Problem:
/datum/example
var/a
var/b

/datum/example/New(text)
world.log << "/datum/example/New: text=\"[text]\""
src.a = "[text]"
src.b = "12345 [text]"

/world/New()
do_the_thing()
del(src)

/proc/do_the_thing()
var/datum/example/thingy = call_ext("bynewtest", "byond:test")()
if(!istype(thingy))
world.log << "thingy failed to initialize"
return
world.log << "thingy: \ref[thingy]"
world.log << "thingy.a: \[[thingy.a]\]"
world.log << "thingy.b: \[[thingy.b]\]"


#include "byondapi.h"
#include "byondapi_cpp_wrappers.h"

extern "C" BYOND_EXPORT CByondValue test(u4c argc, ByondValue argv[]) {
auto example_path = ByondValue("/datum/example");
auto str = ByondValue("hihi!");
auto obj = ByondValue();
auto ret = Byond_New(example_path, &str, 1);
return ret;
}


Expected Results:

Welcome BYOND! (5.0 Beta Version 515.1614)
/datum/example/New: text="hihi!"
thingy: [0x21000000]
thingy.a: [hihi!]
thingy.b: [12345 hihi!]


Actual Results:

Welcome BYOND! (5.0 Beta Version 515.1614)
/datum/example/New: text="hihi!"
thingy: [0x21000000]
thingy.a: [thingy: [0x21000000]]
thingy.b: [12345 hihi!]


Does the problem occur:
Every time? Or how often? Yes
In other games? N/A
In other user accounts? N/A
On other computers? N/A

When does the problem NOT occur?

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Haven't tested

Workarounds: Create a new string, such as by appending a space to the input string in /New:
/datum/example/New(text)
world.log << "/datum/example/New: text=\"[text]\""
src.a = "[text] "
src.b = "12345 [text]"


Just realized I tested on 1614 initially, but I tested again and this bug is still present on 1616.
More weird behavior:
/datum/example
var/a
var/b

/datum/example/New(text)
world.log << "/datum/example/New: text=\"[text]\""
src.a = "[text]"
src.b = "12345 [text]"

/world/New()
do_the_thing()
world.log << "thing done"
del(src)

/proc/do_the_thing()
var/datum/example/thingy = call_ext("bynewtest", "byond:test")()
if(!istype(thingy))
world.log << "thingy failed to initialize"
return
world.log << "thingy: \ref[thingy]"
world.log << "thingy.a: \[[thingy.a]\]"
world.log << "thingy.b: \[[thingy.b]\]"
var/a = 1
a += 42
world.log << "thingy.a 2 \[[thingy.a]\]"


/datum/example/New: text="hihi!"
thingy: [0x21000000]
thingy.a: [thingy: [0x21000000]]
thingy.b: [12345 hihi!]

thing done
Lummox JR resolved issue with message:
Byondapi: Byond_New() double-decref'd its arguments, resulting in runtime errors.