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

Error "opcode #38 (report please)" when to a custom class #43042

Closed
theraot opened this issue Oct 23, 2020 · 14 comments
Closed

Error "opcode #38 (report please)" when to a custom class #43042

theraot opened this issue Oct 23, 2020 · 14 comments

Comments

@theraot
Copy link
Contributor

theraot commented Oct 23, 2020

I found another report of opcode 38: #43023

Godot version:
3.2.4.beta1

OS/device including version:
Windows 10

Issue description:
I created a scene with root node with a script attached that has a custom class. I instantiated the scene, and tried to cast to the custom class. Expected the cast to succeed. Got the following error:

Internal Script Error! - opcode #38 (report please).

Errors panel says:

E 0:00:00.757   call: Condition ' !base_type ' is true. Breaking..:
  <Fuente C++>  modules/gdscript/gdscript_function.cpp:938 @ call()
  <Stack Trace> Core.gd:6 @ _ready()

Steps to reproduce:

  1. Create a new project. Add two (2D) scenes. Let us call them "Main.tscn" and "Item.tscn"
  2. In Item.tscn, attach a script to the root note (A Node2D), with this code:
extends Node2D

class_name Item
  1. In Main.tscn, add a node with an attached script, with this code:
extends Node2D

onready var item = load("Item.tscn");

func _ready():
    var created_item = item.instance() as Item; #error here
    add_child(created_item);

This can be worked around by not casting. Without casting, we can still use call et.al. to interact with the script.

Minimal reproduction project:

Test.zip

@Calinou Calinou added this to the 3.2 milestone Oct 23, 2020
@Calinou Calinou changed the title opcode 38 casting to custom class Error "opcode #38 (report please)" when to a custom class Oct 23, 2020
@theraot
Copy link
Contributor Author

theraot commented Oct 23, 2020

@Calinou It is worth noting that the error on #43023 says:

modules/gdscript/gdscript_function.cpp:837 @ call()

While this one says:

modules/gdscript/gdscript_function.cpp:938 @ call()

Line 837 vs line 938.

@theraot
Copy link
Contributor Author

theraot commented Oct 23, 2020

After having a look at the project from #43023, I tried and found that when I change the code in my project to the following you get the error on line 837:

extends Node2D

onready var item = load("Item.tscn");

func _ready():
    var tmp = item.instance();
    var created_item: Item = tmp; #error here
    add_child(created_item);

@Calinou

@Calinou
Copy link
Member

Calinou commented Oct 23, 2020

@theraot If you can build Godot from source, can you try to bisect the regression? This would be hugely appreciated 🙂

@theraot
Copy link
Contributor Author

theraot commented Oct 23, 2020

@Calinou I'll try. I have not been able to built Godot from source yet. In fact, After my last post here I decided to follow Compiling for Windows. I think my scons setup failed, haven't figured out why yet. Edit: upgraded pip, scons installed.

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

I built commit a03af87 (current head of 3.2 branch)


This code

extends Node2D

onready var item = load("Item.tscn");

func _ready():
    var created_item = item.instance() as Item; #error here
    add_child(created_item);

Gets:

Internal Script Error! - opcode #17 (report please).
E 0:00:00.644   GDScriptFunction::call: Condition ' !base_type ' is true. Breaking..:
  <Fuente C++>  modules\gdscript\gdscript_function.cpp:938 @ GDScriptFunction::call()
  <Stack Trace> Core.gd:6 @ _ready()

This code:

extends Node2D

onready var item = load("Item.tscn");

func _ready():
    var tmp = item.instance();
    var created_item: Item = tmp; #error here
    add_child(created_item);

Gets:

Internal Script Error! - opcode #14 (report please).
E 0:00:00.599   GDScriptFunction::call: Condition ' !base_type ' is true. Breaking..:
  <Fuente C++>  modules\gdscript\gdscript_function.cpp:837 @ GDScriptFunction::call()
  <Stack Trace> Core.gd:7 @ _ready()

I'll try to find out the last commit without this issue.

Edit: f550af9, 900949b, 72d1228, e6a860d, e51fed9 works fine.

8a97e65, 7b3f9eb, ef223f3, 8ca98dd Fails.

I'll narrow it down more.

@Error7Studios
Copy link

Error7Studios commented Oct 24, 2020

Found that this works with Node, Control, and Node2D classes.
Preload() does not cause the error, while load() does.
As stated above, using static typing causes it at .cpp line 837, and casting causes the bug at line 938.
opcode 38 info

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

79f1502 Works
0d8b2d3, 6dffc1e Fails

I'm getting close.

@Error7Studios
Copy link

Don't know if it helps or not, but I just found that load() triggers the error, but preload() doesn't

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

@Error7Studios Perhaps.

My understanding of Godot source is very limited. However, my current hypothesis is that the class is not being registered correctly, and thus when the runtime tries to check the type for the cast, it fails. Perhaps preloads does it correctly and load does not.

Once I figure out what commit introduced the problem, I'd have a better idea of what it is.

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

f388ea0 Works
76a8458, aa0221f Fails

Looking at bca2633, I think it introduced the problem. I'm yet to build it and test it at the time of writing.

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

I can confirm that bca2633 introduced the problem.

I can also confirm that using preload avoids the problem.

bca2633 is intended to fix a leak caused by cyclic references. I guess it did not touch preload, it didn't have to, since preload won't work when there are cyclic references. That explains that only load is affected.

Looking at the diff, I guess the Ref<Script> is causing the checks at gdscript_function.cpp to trip.


About fixing it, I don't know, but I have the source and the means to build it, I might give it go.

@theraot
Copy link
Contributor Author

theraot commented Oct 24, 2020

CC @RandomShaper

@ChainedLupine
Copy link
Contributor

Chiming in, as the "!base_type is true/ISE opcode #17" error is what got me involved.

@akien-mga
Copy link
Member

Fixed by #43049.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants