Closed maxeonyx closed 4 years ago
Here I observe the correct behaviour in the first but not the second:
// this is the line after I applied my "fix"
image.this as *const _ as *const _,
// this is the above line with only a dbg!() added
dbg!(image).this as *const _ as *const _,
Image
is reference-counted. Could it be that the pattern match (or dbg
invocation) consumed the value, causing the image to be dropped? Pointers don't have lifetimes, which could explain why it passed compilation. No, that was a bad theory. Actually I think it might explain the first case:
let mut argument_buffer : [*const libc::c_void; 2] = [
if let Some(arg) = image {
// Image is not Copy, so arg is moved here
arg.this as *const _ as *const _
// arg is dropped when it goes out of scope. When its destructor runs, the `Ref<Image>`
// that `arg.this` is pointing to gets set to null, since it would be the only reference
} else { ptr::null() },
(&layer) as *const _ as *const _,
];
// here argument_buffer[0] is not null, but the `Ref` it is pointing to is containing a null reference
// drop(image); // If this theory is true, then this won't compile, since `image` is already dropped
If argument_buffer[0]
is not null but the Godot Ref
is, then this might explain the original bug. I'm not sure about the dbg!
one though.dbg!
could be explained because it returns the value moved in as a temporary one, for which no let binding was created. That value can be dropped by the compiler immediately after it's used.
If this theory is correct, then if let Some(arg) = &image
should fix the bug.
Yeah it's the godot Ref that's null. Godot is warning me that condition !img.is_valid is true
, which means that the Ref
@toasteater You're right - adding the borrow in the destructuring fixes the issue.
if let Some(arg) = &image { arg.this as *const _ as *const _ } else { ptr::null() },
Hi -
I am making a small program to create procedural 3D (volumetric) textures.
Currently I am very confused. I have just encountered an issue with the bindings where a parameter was being incorrectly set to null. The API in question takes an
Option<Image>
parameter.I have fixed my problem by editing the bindings files and changing the parameter type from
Option<Image>
to justImage
, and replacing theif let Some(arg) = image { ... } else { ptr::null() }
line.Obviously modifying the binding code is not ideal. I was wondering if I am doing something wrong, or whether this is a bug.
Below is my before and after versions of the files.
tex_3d.rs (my code) (before)
tex_3d.rs (my code) (after)
bindings_types.rs (before)
bindings_types.rs (after)
bindings_methods.rs (before)
bindings_methods.rs (after)