From 6909309ca018435e8bf0d908282599c5e642bd78 Mon Sep 17 00:00:00 2001 From: nikitalita <69168929+nikitalita@users.noreply.github.com> Date: Sun, 18 May 2025 02:33:56 -0700 Subject: [PATCH] Bump script bytecode version after token enum change --- modules/gdscript/gdscript_tokenizer.h | 1 + modules/gdscript/gdscript_tokenizer_buffer.cpp | 17 +++++++---------- modules/gdscript/gdscript_tokenizer_buffer.h | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index cfaa2aae05..7641c93e09 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -45,6 +45,7 @@ public: }; struct Token { + // If this enum changes, please increment the TOKENIZER_VERSION in gdscript_tokenizer_buffer.h enum Type { EMPTY, // Basic diff --git a/modules/gdscript/gdscript_tokenizer_buffer.cpp b/modules/gdscript/gdscript_tokenizer_buffer.cpp index d9b6ec68a2..9f0e96b8c3 100644 --- a/modules/gdscript/gdscript_tokenizer_buffer.cpp +++ b/modules/gdscript/gdscript_tokenizer_buffer.cpp @@ -33,8 +33,6 @@ #include "core/io/compression.h" #include "core/io/marshalls.h" -#define TOKENIZER_VERSION 100 - int GDScriptTokenizerBuffer::_token_to_binary(const Token &p_token, Vector &r_buffer, int p_start, HashMap &r_identifiers_map, HashMap &r_constants_map) { int pos = p_start; @@ -143,7 +141,7 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector &p_buffer) ERR_FAIL_COND_V(p_buffer.size() < 12 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA); int version = decode_uint32(&buf[4]); - ERR_FAIL_COND_V_MSG(version > TOKENIZER_VERSION, ERR_INVALID_DATA, "Binary GDScript is too recent! Please use a newer engine version."); + ERR_FAIL_COND_V_MSG(version != TOKENIZER_VERSION, ERR_INVALID_DATA, "Binary GDScript is not compatible with this engine version."); int decompressed_size = decode_uint32(&buf[8]); @@ -161,10 +159,10 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector &p_buffer) uint32_t identifier_count = decode_uint32(&buf[0]); uint32_t constant_count = decode_uint32(&buf[4]); uint32_t token_line_count = decode_uint32(&buf[8]); - uint32_t token_count = decode_uint32(&buf[16]); + uint32_t token_count = decode_uint32(&buf[12]); - const uint8_t *b = &buf[20]; - total_len -= 20; + const uint8_t *b = &buf[16]; + total_len -= 16; identifiers.resize(identifier_count); for (uint32_t i = 0; i < identifier_count; i++) { @@ -292,14 +290,13 @@ Vector GDScriptTokenizerBuffer::parse_code_string(const String &p_code, } Vector contents; - contents.resize(20); + contents.resize(16); encode_uint32(identifier_map.size(), &contents.write[0]); encode_uint32(constant_map.size(), &contents.write[4]); encode_uint32(token_lines.size(), &contents.write[8]); - encode_uint32(0, &contents.write[12]); // Unused, kept for compatibility. Please remove at next `TOKENIZER_VERSION` increment. - encode_uint32(token_counter, &contents.write[16]); + encode_uint32(token_counter, &contents.write[12]); - int buf_pos = 20; + int buf_pos = 16; // Save identifiers. for (const StringName &id : rev_identifier_map) { diff --git a/modules/gdscript/gdscript_tokenizer_buffer.h b/modules/gdscript/gdscript_tokenizer_buffer.h index 163dbe6fe8..74de533801 100644 --- a/modules/gdscript/gdscript_tokenizer_buffer.h +++ b/modules/gdscript/gdscript_tokenizer_buffer.h @@ -39,6 +39,7 @@ public: COMPRESS_ZSTD, }; + static constexpr uint32_t TOKENIZER_VERSION = 101; static constexpr uint32_t TOKEN_BYTE_MASK = 0x80; static constexpr uint32_t TOKEN_BITS = 8; static constexpr uint32_t TOKEN_MASK = (1 << (TOKEN_BITS - 1)) - 1;