Skip to content

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

Open

Description

@paulmenage

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?

Activity

  1. paulmenage commented on Jun 14, 2018

    @paulmenage
    Author

    And the same issue for String::split_floats()

  2. karroffel commented on Jun 15, 2018

    @karroffel
    Contributor

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

  3. BastiaanOlij commented on Nov 23, 2018

    @BastiaanOlij
    Collaborator

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

  4. added
    bug
    on Nov 23, 2018
  5. Zylann commented on Jan 7, 2021

    @Zylann
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions