#Trying to remediate difference in instance id between 64 bit C++ and 32 bit Godot ids

1 messages · Page 1 of 1 (latest)

safe condor
#

I'm looking for a malformed texture2d giving me an error

E 0:00:03:0667 get_height: Required virtual method Texture2D::_get_height must be overridden before calling.
<C++ Error> Method/function failed. Returning: 0
<C++ Source> scene\resources\texture.cpp:53 @ get_height()

while debugging , i built the godot client such that it would give me the instance id of a texture giving this error, but c++ emits 64 bit ids apparently? And Godot cannot take those 64 bit ids to search for them as far as I've been able to make work. Does anyone know how to convert a c++ id to a godot id?

safe condor
#

Actually a better way of putting this, i think, is, how do i print an instance id in C++ such that i can read it out in godot and find the relevant instance?

maiden fractal
#

In gdscript you can call instance_from_id(id) which will be valid for the debug session.

safe condor
#

sorry, i should be more specific

#

i'm trying to get the id out of cpp in a way that i can use it in godot in that exact function

maiden fractal
#

Or is it that the c++ output is giving an unsigned int?

safe condor
#

right now in texture.cpp i have this

int Texture2D::get_height() const {
    int ret = 0;
    if (GDVIRTUAL_IS_OVERRIDDEN(_get_height)) {
        GDVIRTUAL_CALL(_get_height, ret);
    } else {
        WARN_PRINT(vformat("Missing _get_height override in: class=%s, path=%s, id=%s",
            get_class(),
            (Object::cast_to<Resource>(this) && Object::cast_to<Resource>(this)->get_path() != String()) ?
                Object::cast_to<Resource>(this)->get_path() : "[unknown]",
                String::num_int64((int64_t)get_instance_id())));
        CRASH_NOW_MSG("Forced crash for debugging purposes");

        // Crash like the macro would
        ERR_FAIL_V_MSG(0, "Required virtual method Texture2D::_get_height must be overridden before calling.");
    }
    return ret;
}
#

but String::num_int64((int64_t)get_instance_id()))); is returning a negative number, only positive if it is uint64

#

but a uint64 doesn't fit into instance_from_id

#

ignore the CRASH_NOW part

#

that was me trying other stuff

#

to get more specific, the path is returning [unknown] as well, hence me trying to dig

#

and the class type is Texture2D

maiden fractal
#

It should be as simple as using the signed int64

safe condor
#

then let me try that again real quick -- is it alright that it's negative?

maiden fractal
#

Yeah

safe condor
#

here's what happened:

W 0:00:03:0010   get_height: Missing _get_height override in: class=Texture2D, path=[unknown], id=-9223371851684635845
  <C++ Source>   scene\resources\texture.cpp:46 @ get_height()

so far so good,

#

put it into a textedit as a hack to have a runtime button to search for the resource

#

made the textedit a little small, but it was a copypaste job

#

didn't find it though

#
resource id -9223371851684635845
Failed to load resource with ID:-9223371851684635845
#
extends Node

@onready var button: Button = $Button
@onready var text_edit: TextEdit = $TextEdit

func _ready():
    button.pressed.connect(_on_button_pressed)

func _on_button_pressed():
    var resource_id = text_edit.text.strip_edges()
    if resource_id == "":
        print("No ID entered.")
        return
        
    print("resource id ", resource_id)
    var resource: Resource = instance_from_id(int(resource_id))
    if resource:
        print("Resource loaded successfully:", resource)
    else:
        print("Failed to load resource with ID:", resource_id)
#

is it possible that means the resource got nixed or something before i had the chance to look for it?

maiden fractal
#

Is it the same debug session? Like is the scene being run from the debugger?

safe condor
#

yep

#

i hit the "start" button, read the debug logs, put it into my textedit, hit my button -- all without stopping the game

#

oh

#

interesting

maiden fractal
#

Hm. To be extra clear, it would be run like "godot.exe pathtoproject" from the debugger with the main scene set to the problem scene?

safe condor
#

so the log shows up many times and the last time it shows up, i got a resource

#

it shows up ~8 times

#

we're making progress

safe condor
#

i'm just in the godot client hitting the "start" button, and building elements to allow me to interact

#

but this process has allowed me to get at least one hit for a resource

#

so, very exciting

#

let's try and find out more about it

#

i'd be interested in debugger docs

#

for context, i'm using c#, so for debugging i use rider

#

but

#

wait why am i not doing that

#

well anyway i was doing gdscript because it's faster to iterate

maiden fractal
#

(i was referring to the c++ debugger if it's a custom build)

safe condor
#

that makes sense

#

i'll take a moment to try and get more information about the resources i have been able to hit, and see if i need to go more hardocre or if i can solve my problems here

maiden fractal
#

((if you use the c++ debugger in future, Godot needs to be run with the commandline flags as the project selector, the editor, and the game are 3 different instances, launching normally the debugger would quit after the project list!))

safe condor
#

excelente

#

say i have a resource, what is some information i could try to discern where the heck it came from?

#

or where it even is in the context of the running project?

maiden fractal
#

for this case, what's it's get_class() say?

safe condor
#

Texture2D

maiden fractal
#

Bah. So it really is an "abstract" type. Does it have a resource uid?

safe condor
#

what's the property for that?

#

just .uid?

#

if so, then no -- threw an error at runtime

maiden fractal
#

Does it have an rid? get_rid()

safe condor
#

resource id -9223371824404882502
Resource loaded successfully:<Texture2D#-9223371824404882502>
No explicit owner metadata.
Class:Texture2D
rid:RID(0)

#

looks like a trivial value to me, lmk if i can pull anything else out of it

#

the annoying thing is that i've been looking at the commit that cause this, and it's really just adding a bunch of pngs and updating some tscns, with nothing that looks crazy

#

i can delete the pngs and the error keeps happening and so on

maiden fractal
#

Rid 0. This is as null a texture can be without actually being null. I have an idea though.

@tool
class_name MyTexture
extends Texture2D

func _get_height():
  return 64

...

...

the_bad_resource.set_script(load("res://path_to_my_tex.gd"))

It might be possible to force a texture to draw or reveal a trace if a partial implement of all the base funcs is attached..

safe condor
#

let's take a look

#

oh that's cute

#

okay i'll try

#

i'll override get_width as well because that's a problem too

#

while im at it, what on earth could be generally causing this?

#

is it possible one of my resources that should have a texture has absolutely nothing on it?

maiden fractal
#

Right now, no idea

safe condor
#

i'm thinking of trying to cherrypick the whole commit line by line

#

but i might as well try this first

#

it's only a hundred lines or so in total

#

anyway i'll get on it

#

i guess it worked, but i can't see anything. screen's a little busy anyway in general

#

but it didn't crash

#

maybe i can make it really big and put something on it?

maiden fractal
#
_draw(to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool):
  print(self, ": ", pos)

See if you can get info from the draw functions

safe condor
#
        resource.set_script(load("res://debug.gd"))
@tool
class_name MyTexture
extends Texture2D

func _get_height():
  return 64

func _get_width():
  return 64
#

on it

#

three interesting debugger messages

#
W 0:00:18:0425   The parameter "to_canvas_item" is never used in the function "_draw()". If this is intended, prefix it with an underscore: "_to_canvas_item".
  <GDScript Error>UNUSED_PARAMETER
  <GDScript Source>debug.gd:11
W 0:00:18:0425   The parameter "modulate" is never used in the function "_draw()". If this is intended, prefix it with an underscore: "_modulate".
  <GDScript Error>UNUSED_PARAMETER
  <GDScript Source>debug.gd:11

W 0:00:18:0425   The parameter "transpose" is never used in the function "_draw()". If this is intended, prefix it with an underscore: "_transpose".
  <GDScript Error>UNUSED_PARAMETER
  <GDScript Source>debug.gd:11
#

and nothing printed as far as i can tell

#
resource id -9223371823196922920
Resource loaded successfully:<Texture2D#-9223371823196922920>
No explicit owner metadata.
Class:Texture2D
rid:RID(0)
#

oic those errors are just informing me about syntax sugar aren't they

#

hmm, now i'm not sure the script is doing anything

#

i added a print statement into _get_width and it didn't show

maiden fractal
#

Damn.

safe condor
#

well thanks for helping out, i think i might be on the "reapply the changeset until it breaks" plan

#

i have a hard time believing that will fail

#

who doesn't love modifying tscns by hand

#

this is really just me being an annoying purist, but also, i'm so curious...

maiden fractal
#

Mm. Don't forget to clear the .godot cache if not done already

safe condor
#

found 'er

#

that turned out to be really dumb

#

an autoloader i wrote got misconfigured in a way i didn't notice, and so some other code that was not changed in a long time i guess for the very first time hit its final fallback of myTexture = new()

#

sorry it wound up being anticlimactic, but also thanks!

#

i didn't even know i had that new() call in there

#

also a bit odd that a new() texture explodes like that, but i guess i can see the idea?