Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

godot-cpp String::split() incorrectly casting godot_array to PoolStringArray? #144

Open
paulmenage opened this issue Jun 14, 2018 · 4 comments
Labels
bug This has been identified as a bug

Comments

@paulmenage
Copy link

paulmenage commented Jun 14, 2018

Trying to use String.split() from C++ GDNative resulted in crashes when trying to access the values, and bogus size() values.

It looks like godot-cpp/src/core/String.cpp is directly casting a godot_array into a PoolStringArray, which AFAICS are distinct types - shouldn't it be doing something more like this (which does appear to do the right thing for me)?

    godot_array arr = godot::api->godot_string_split(&_godot_string, &divisor._godot_string);
    godot_pool_string_array result;
    godot::api->godot_pool_string_array_new_with_array(&result, &arr);
    godot::api->godot_array_destroy(&arr);
    return *(PoolStringArray *)&result;

Or even better, godot_string_split() should be returning a real pool_array to start with?

@paulmenage
Copy link
Author

And the same issue for String::split_floats()

@karroffel
Copy link
Contributor

Oh yes, that's an error, I'll see if I can fix it today

@BastiaanOlij
Copy link
Collaborator

@karroffel this code has changed a bit since June, looks like this was fixed?

@BastiaanOlij BastiaanOlij added the bug This has been identified as a bug label Nov 23, 2018
@Zylann
Copy link
Collaborator

Zylann commented Jan 7, 2021

Just tested this after PR #490

	String s("Hello World! This string was split");
	PoolStringArray p = s.split(" ");
	Godot::print(String("String was split in ") + String::num_int64(p.size()));
	PoolStringArray::Read r = p.read();
	for (int i = 0; i < p.size(); ++i) {
		Godot::print(r[i]);
	}

Result:

String was split in 6
Hello
World!
This
string
was
split

No errors, no crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This has been identified as a bug
Projects
None yet
Development

No branches or pull requests

4 participants