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

Custom class (class_name) not working with 3.2.3 RC3, but it works in RC2 #40991

Closed
ChronoDK opened this issue Aug 3, 2020 · 16 comments · Fixed by #41025
Closed

Custom class (class_name) not working with 3.2.3 RC3, but it works in RC2 #40991

ChronoDK opened this issue Aug 3, 2020 · 16 comments · Fixed by #41025

Comments

@ChronoDK
Copy link

ChronoDK commented Aug 3, 2020

Godot version:
3.2.3 RC3

OS/device including version:
Windows 10

Issue description:
I found some weird difference between RC2 and RC3 that I can't figure out.

My HTML5 build crashes when a custom class is included, and complains "identifier "SafeNum" isn't a valid type (not a script or class), or couldn't be found on base "self"."

The class DOES work in RC2 (and everything before that), so this must be a new bug.

Steps to reproduce:
Just include my class file (that I pasted below), and use it like this:
var diamonds:SafeNum = SafeNum.new(1)

Minimal reproduction project:

class_name SafeNum
extends Reference

var _num = null
var _permutator = null
var _permutation = null

class DynNum:
    var _num:float
    func _init(n):
        _num = n
        pass
    func getValue():
        return _num

func _init(n):
    _setUnchecked(n)
    pass

func _setUnchecked(n):
    _num = DynNum.new(n)
    _permutator = DynNum.new(randf()+1.0)
    _permutation = DynNum.new(_num.getValue() * _permutator.getValue())
    return self

func _setChecked(n):
    if _permutation.getValue() != (_num.getValue() * _permutator.getValue()):
        printerr("MEMORY CHEAT DETECTED")
    return _setUnchecked(n)

func getValue():
    _setChecked(_num.getValue())
    return _num.getValue()
    
func setValue(n):
    return _setChecked(n)
    
func plus(n):
    return _setChecked(_num.getValue() + n)

func minus(n):
    return _setChecked(_num.getValue() - n)

func multiply(n):
    return _setChecked(_num.getValue() * n)
    
func divide(n):
    return _setChecked(_num.getValue() / n)```

Bugsquad edit (keywords for easier searching): named class

@Calinou
Copy link
Member

Calinou commented Aug 3, 2020

If you can compile from source, can you try bisecting the regression, please? It should only require building an HTML5 export template a few times, since the commit range between 3.2.3rc2 and 3.2.3rc3 is quite narrow.

@Faless
Copy link
Collaborator

Faless commented Aug 3, 2020

Just include my class file (that I pasted below), and use it like this:
var diamonds:SafeNum = SafeNum.new(1)

Did you forget to add:
class_name SafeNum in the attached file? I can't see where you define SafeNum as the name of that script.
Using class_name seems to work for me.

@ChronoDK
Copy link
Author

ChronoDK commented Aug 3, 2020

@Faless Oh, I can see I forgot to paste the first line of the file here. class_name SafeNum is indeed at the top of the file. Very strange that it works for you though. I will have to do some more testing tomorrow, and maybe try bisecting as @Calinou suggests.

@ChronoDK
Copy link
Author

ChronoDK commented Aug 3, 2020

@Faless Do you have it working in an HTML5 build or just in the editor? It is only in the HTML5 build that it doesn't work for me.

@Faless
Copy link
Collaborator

Faless commented Aug 3, 2020 via email

@Faless
Copy link
Collaborator

Faless commented Aug 3, 2020

I can confirm the issue. Weird... I'll start bisecting.

@Faless
Copy link
Collaborator

Faless commented Aug 3, 2020

Offending commit seems to be: 4f9ca00

git bisect start
# good: [400a7800503743265b7ede76ffb543907e57886a] Revert "Allow Area2D and 3D mouse events without a collision layer"
git bisect good 400a7800503743265b7ede76ffb543907e57886a
# bad: [23b553ba0603161346526e1821bff5002520173c] Merge pull request #40914 from akien-mga/3.2-ci-emscripten-1.39.20
git bisect bad 23b553ba0603161346526e1821bff5002520173c
# good: [fe4aa393f093cd4e37409e2d1b0b68e8e05abd35] Merge pull request #40803 from aaronfranke/3.2_revert-dir
git bisect good fe4aa393f093cd4e37409e2d1b0b68e8e05abd35
# bad: [2987fb3b45d445e60fe136bd7a3cee94ff8f26ca] Improve the `EditorInterface.get_editor_viewport()` description
git bisect bad 2987fb3b45d445e60fe136bd7a3cee94ff8f26ca
# bad: [4a0568b6098eae738ba75f7d1c9202c245dbde9b] Document how to perform advanced string splitting using RegEx
git bisect bad 4a0568b6098eae738ba75f7d1c9202c245dbde9b
# bad: [4f9ca00294e99f9fa02ed6ea86b124c396d12eff] Check if global class file still exists before registering it
git bisect bad 4f9ca00294e99f9fa02ed6ea86b124c396d12eff
# good: [36b746d90393299b81ecb991f4aa94a8d742fd11] Merge pull request #40822 from Calinou/doc-canvasitem-draw_multiline_colors-antialiased
git bisect good 36b746d90393299b81ecb991f4aa94a8d742fd11
# first bad commit: [4f9ca00294e99f9fa02ed6ea86b124c396d12eff] Check if global class file still exists before registering it

@Faless
Copy link
Collaborator

Faless commented Aug 3, 2020

Probably caused by checking the file path, instead of the remapped path. (res://*.gd vs res://*.gdc)

@ChronoDK
Copy link
Author

ChronoDK commented Aug 4, 2020

That's cool! I would probably have spend all day trying that bisect stuff, cause compiling is slow for me :-)

Let me know if there is anything I can do.

@Xrayez
Copy link
Contributor

Xrayez commented Aug 4, 2020

If this is specific to HTML5, I'm curious why #41025 fixes it then? (I haven't tested it myself though). It wouldn't work on all other platforms then?..

@mbrlabs
Copy link
Contributor

mbrlabs commented Aug 4, 2020

This is probably not just an HTML5 thing. The same thing just happend to me on Android:

2020-08-04 22:32:07.600 18179-18179/io.mbrlabs.polyrun E/chromium: [ERROR:filesystem_posix.cc(62)] mkdir /data/user/0/io.mbrlabs.polyrun/cache/WebView/Crashpad: No such file or directory (2)
2020-08-04 22:32:08.130 18179-18444/io.mbrlabs.polyrun E/godot: **SCRIPT ERROR**: Parse Error: The identifier "Crystal" isn't a valid type (not a script or class), or couldn't be found on base "self".
2020-08-04 22:32:08.130 18179-18444/io.mbrlabs.polyrun E/godot:    At: res://Utils/CurrentGame.gdc:47:GDScript::load_byte_code() - Parse Error: The identifier "Crystal" isn't a valid type (not a script or class), or couldn't be found on base "self".
2020-08-04 22:32:08.130 18179-18444/io.mbrlabs.polyrun E/godot: **ERROR**: Method failed. Returning: ERR_PARSE_ERROR
2020-08-04 22:32:08.130 18179-18444/io.mbrlabs.polyrun E/godot:    At: modules/gdscript/gdscript.cpp:801:load_byte_code() - Method failed. Returning: ERR_PARSE_ERROR
2020-08-04 22:32:08.130 18179-18444/io.mbrlabs.polyrun E/godot: **ERROR**: Cannot load byte code from file 'res://Utils/CurrentGame.gdc'.

I didn't test this on rc1 or rc2, just rc3. This is not happening in 3.2.2.stable.

@Calinou Calinou changed the title Custom class not working in HTML5 build with 3.2.3 RC3, but it works in RC2 Custom class not working with 3.2.3 RC3, but it works in RC2 Aug 4, 2020
@vicguedez
Copy link

Just came across this in Android and Windows. I use two scripts with class_name, I tried with extends Reference and without extends but its all the same, 3.2.2 RC2 works fine.

Screenshot_1

@bluebarnacles
Copy link

bluebarnacles commented Aug 8, 2020

I have a similar error on Android in 3.2.3rc3. The typechecker causes an error on my class, which is defined in a MyObject.gd with class_name MyClass. It works fine on Android in 3.2.3rc2. In my case, my class is used in an autoload scene, so it prevents the autoload from loading. Here is the logcat from the error:

2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **SCRIPT ERROR**: Parse Error: The identifier "MyClass" isn't a valid type (not a script or class), or couldn't be found on base "self".
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: res://Global.gdc:6:GDScript::load_byte_code() - Parse Error: The identifier "MyClass" isn't a valid type (not a script or class), or couldn't be found on base "self".
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Method failed. Returning: ERR_PARSE_ERROR
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: modules/gdscript/gdscript.cpp:801:load_byte_code() - Method failed. Returning: ERR_PARSE_ERROR
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Cannot load byte code from file 'res://Global.gdc'.
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: modules/gdscript/gdscript.cpp:2282:load() - Condition "err != OK" is true. Returned: RES()
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Failed loading resource: res://Global.gdc.
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: core/io/resource_loader.cpp:278:_load() - Condition "found" is true. Returned: RES()
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: res://Global.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Global.gd
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: scene/resources/resource_format_text.cpp:440:poll() - res://Global.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Global.gd
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Failed to load resource 'res://Global.tscn'.
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: core/io/resource_loader.cpp:208:load() - Condition "err != OK" is true. Returned: RES()
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Failed loading resource: res://Global.tscn.
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: core/io/resource_loader.cpp:278:_load() - Condition "found" is true. Returned: RES()
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Can't autoload: res://Global.tscn
2020-08-08 09:36:50.555 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: main/main.cpp:1757:start() - Condition "res.is_null()" is true. Continuing.
2020-08-08 09:36:50.598 25171-25197/org.godotengine.androidtypecheckerro E/godot: **ERROR**: Node not found: /root/Global.
2020-08-08 09:36:50.598 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: scene/main/node.cpp:1381:get_node() - Condition "!node" is true. Returned: __null
2020-08-08 09:36:50.598 25171-25197/org.godotengine.androidtypecheckerro E/godot: **SCRIPT ERROR**: Invalid get index 'state' (on base: 'null instance').
2020-08-08 09:36:50.598 25171-25197/org.godotengine.androidtypecheckerro E/godot:    At: res://Main.gdc:12:_ready() - Invalid get index 'state' (on base: 'null instance').

@MrZak-dev
Copy link

MrZak-dev commented Aug 10, 2020

Same issue with me #41060 (RC3 mono), unable to identify class file by name .

@98teg
Copy link
Contributor

98teg commented Aug 10, 2020

I run into a similar issue, although I don't know if it is the same because it shows a different error message:

Godot Engine v3.2.3.rc.custom_build.23b553ba0 - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GTX 1050 Ti/PCIe/SSE2
 
SCRIPT ERROR: GDScript::load_byte_code: Parse Error: The identifier "ExampleClass" isn't declared in the current scope.
   At: res://Control.gdc:5.
ERROR: load_byte_code: Method failed. Returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:801.
ERROR: load: Condition "err != OK" is true. Returned: RES()
   At: modules/gdscript/gdscript.cpp:2282.
ERROR: _load: Condition "found" is true. Returned: RES()
   At: core/io/resource_loader.cpp:278.
ERROR: poll: res://Control.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Control.gd
   At: scene/resources/resource_format_text.cpp:440.
ERROR: load: Condition "err != OK" is true. Returned: RES()
   At: core/io/resource_loader.cpp:208.
ERROR: _load: Condition "found" is true. Returned: RES()
   At: core/io/resource_loader.cpp:278.
ERROR: start: Condition "!scene" is true. Returned: false
   At: main/main.cpp:1944.
WARNING: cleanup: ObjectDB instances leaked at exit (run with --verbose for details).
   At: core/object.cpp:2135.
ERROR: clear: Resources still in use at exit (run with --verbose for details).
   At: core/resource.cpp:477.

Executing in the editor is fine, but it crashes when I export the project and then execute it. However, if I copy the folder that contains the scripts with the classes on the same folder that contains the executable, it runs.

@HEAVYPOLY
Copy link
Contributor

Confirmed here on Mac and Windows export.
extends ClassName
crashes the exported project, but runs fine in editor (3.2.3 RC3)

Project exported fine on 3.2.2

@Calinou Calinou changed the title Custom class not working with 3.2.3 RC3, but it works in RC2 Custom class (class_name) not working with 3.2.3 RC3, but it works in RC2 Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.