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

Fixed PackedByteArray GDScript functions #39100

Merged
merged 1 commit into from Sep 7, 2020

Conversation

Wavesonics
Copy link
Contributor

@Wavesonics Wavesonics commented May 27, 2020

It looks like with the switch to PackedByteArray from the PoolArray types, the GDScript functions weren't updated correctly.
p_self._data.packed_array needs to be used instead of p_self._data._mem

These functions are now fixed:

  • _call_PackedByteArray_get_string_from_ascii
  • _call_PackedByteArray_get_string_from_utf8
  • _call_PackedByteArray_compress
  • _call_PackedByteArray_decompress
  • _call_PackedByteArray_hex_encode

Edit: Fixes #36611

@Wavesonics
Copy link
Contributor Author

Wavesonics commented May 27, 2020

Tested with this script:

func _ready():
	var plain := "Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  Test PBA functions  "
	var utf8Bytes := plain.to_utf8()
	print(utf8Bytes)
	print("utf8Bytes: %d" % utf8Bytes.size())
	
	var xStr := utf8Bytes.get_string_from_utf8()
	print("xStr: " + xStr)
	
	var compressedBytes := utf8Bytes.compress(File.COMPRESSION_GZIP)
	
	print("compressedBytes: %d" % compressedBytes.size())
	
	var decompressedBytes := compressedBytes.decompress(utf8Bytes.size(), File.COMPRESSION_GZIP)
	
	print("decompressedBytes: %d" % decompressedBytes.size())
	
	var decStr := decompressedBytes.get_string_from_utf8()
	print("decStr: %d" % decStr.length())
	print("'%s'" % decStr)
	
	var decStrAscii := decompressedBytes.get_string_from_ascii()
	print("decStr: %d" % decStrAscii.length())
	print("'%s'" % decStrAscii)

core/variant_call.cpp Outdated Show resolved Hide resolved
p_self._data.packed_array needs to be used instead of p_self._data._mem

printline
Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 🏅 !

@Faless Faless merged commit 8eb295c into godotengine:master Sep 7, 2020
@Faless
Copy link
Collaborator

Faless commented Sep 7, 2020

Thanks!

@realkotob
Copy link
Contributor

Would be nice if this can be cherry-picked to 3.2.x in the next few months as I'm using these compression functions in production atm.

@nathanfranke
Copy link
Contributor

Can't be cherry picked, because PackedPool. Is this same issue in 3.2? Someone can make a PR specifically for 3.2

@realkotob
Copy link
Contributor

Well now that you mention it, I think this isn't an issue on 3.x, I just mixed up between projects.

I'll open a new issue if it comes up with the 3.x branch instead of master.

@Wavesonics Wavesonics deleted the pool-byte-array-fix branch December 2, 2020 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project crash when using PackedByteArray.compress
5 participants