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

Avoid crash in Variant constructor from nullptr Object* #659

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

groud
Copy link
Member

@groud groud commented Nov 22, 2021

I am not sure about what I am doing, but this at least avoids a crash in my case.

The crash used to happen when generating the docs, while I had one of my extension's class property referencing another class (extending Resource):

ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "magica_voxel_data", PROPERTY_HINT_RESOURCE_TYPE, "MagicaVoxelData"), "set_magica_voxel_data", "get_magica_voxel_data");

I suppose this fix does not really fix the underlying problem, but it avoids a crash. Which is likely a first good step IMO.

@groud groud added bug This has been identified as a bug crash labels Nov 22, 2021
@BastiaanOlij
Copy link
Collaborator

I think this may be a worth while change because we can be getting a nullptr for other (valid) reasons as well. But indeed looking at the bigger problem of the documentation logic trying to figure out what type of object is returned so it can interrogate its meta data, that probably won't be solved by this change.

I have no idea what the proper fix there is. Can we have a typed nil object?

@groud
Copy link
Member Author

groud commented Nov 23, 2021

I have no idea what the proper fix there is. Can we have a typed nil object?

Apparently, reading the engine code, we can. Maybe a better fix is thus to call from_type_constructor[OBJECT](ptr(), const_cast<GodotObject **>(nullptr)); instead when v is null.

I'll check if it works and if so, I'll update the PR.

@groud
Copy link
Member Author

groud commented Nov 23, 2021

Alright, I updated the PR so that it still calls the constructor function with the right Object type. I believe it is the right approach there.

Copy link
Collaborator

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into it crashing here to on the cast, seems like a solid fix.

@BastiaanOlij BastiaanOlij merged commit 50512f0 into godotengine:master Nov 25, 2021
@akien-mga akien-mga added this to the 4.0 milestone Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This has been identified as a bug crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants