Skip to content

Commit 7734ff6

Browse files
committed
Improve src/pythonscript.c check of params provided by Godot at plugin init
1 parent 602f9d0 commit 7734ff6

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/pythonscript.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,12 @@ DLL_EXPORT GDExtensionBool pythonscript_init(
339339
}
340340
state = ENTRYPOINT_CALLED;
341341

342-
(void) p_library; // acknowledge unreferenced parameter
343-
if (p_get_proc_address == NULL || r_initialization == NULL) {
342+
if (p_get_proc_address == NULL || p_library == NULL || r_initialization == NULL) {
344343
printf("Pythonscript: Invalid init parameters provided by Godot (this should never happen !)\n");
345344
goto error;
346345
}
347-
// `pythonscript_gdextension` must be set as early as possible given it is never null-pointer
348-
// checked, especially in the Cython modules
346+
// `pythonscript_gdextension_*` must be set as early as possible given it is never
347+
// null-pointer checked, especially in the Cython modules
349348
pythonscript_gdextension_get_proc_address = p_get_proc_address;
350349
pythonscript_gdextension_library = p_library;
351350

@@ -391,27 +390,18 @@ DLL_EXPORT GDExtensionBool pythonscript_init(
391390
GDExtensionInterfaceGetGodotVersion get_godot_version = (GDExtensionInterfaceGetGodotVersion)p_get_proc_address("get_godot_version");
392391
get_godot_version(&godot_version);
393392
}
394-
if (godot_version.major != GODOT_VERSION_MAJOR) {
395-
// Don't use GD_PRINT_ERROR here given we don't even know if it is available !
396-
printf(
397-
"Pythonscript: Incompatible Godot version (expected ~%d.%d, got %s)\n",
398-
GODOT_VERSION_MAJOR,
399-
GODOT_VERSION_MINOR,
400-
godot_version.string
401-
);
402-
goto error;
403-
}
404-
if (godot_version.minor != GODOT_VERSION_MINOR) {
393+
if (godot_version.major != GODOT_VERSION_MAJOR || godot_version.minor < GODOT_VERSION_MINOR) {
405394
char buff[256];
406395
snprintf(
407396
buff,
408397
sizeof(buff),
409-
"Pythonscript: extension is built for Godot ~%d.%d, but your are running %s. This may cause issues !\n",
398+
"Pythonscript: Incompatible Godot version (expected ~%d.%d, got %s)\n",
410399
GODOT_VERSION_MAJOR,
411400
GODOT_VERSION_MINOR,
412401
godot_version.string
413402
);
414-
GD_PRINT_WARNING(buff);
403+
GD_PRINT_ERROR(buff);
404+
goto error;
415405
}
416406

417407
// Initialize as early as possible, this way we can have 3rd party plugins written

0 commit comments

Comments
 (0)