Fix T83878: Crash right-clicking in Asset Browser with no asset active

Data of the File Browser context callback needs to be validated and
return `CTX_RESULT_NO_DATA` if the context member is valid but not set
in the current context.
This commit is contained in:
Julian Eisel 2020-12-17 11:20:12 +01:00
parent 7e535499d5
commit 6203a3ee68
Notes: blender-bot 2023-02-14 08:49:53 +01:00
Referenced by issue #83878, Crash when right-click in Asset Browser
1 changed files with 11 additions and 2 deletions

View File

@ -803,16 +803,25 @@ static int /*eContextResult*/ file_context(const bContext *C,
if (CTX_data_equals(member, "active_file")) {
FileDirEntry *file = filelist_file(sfile->files, params->active_file);
if (file == NULL) {
return CTX_RESULT_NO_DATA;
}
CTX_data_pointer_set(result, &screen->id, &RNA_FileSelectEntry, file);
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "id")) {
const FileDirEntry *file = filelist_file(sfile->files, params->active_file);
if (file == NULL) {
return CTX_RESULT_NO_DATA;
}
ID *id = filelist_file_get_id(file);
if (id) {
CTX_data_id_pointer_set(result, id);
if (id == NULL) {
return CTX_RESULT_NO_DATA;
}
CTX_data_id_pointer_set(result, id);
return CTX_RESULT_OK;
}