Browse Source

interrogate: generated property getter should copy in some cases

This is to fix eg. public ButtonHandle members from being returned as const reference, which means they won't outlive the struct they are accessed on, a recipe for obscure crashes.

The is_trivial() criterium for this to apply is admittedly really arbitrary; I haven't really figured out what the right criterium should be, but it's better than hardcoding ButtonHandle.
rdb 7 years ago
parent
commit
ad3b145951
1 changed files with 2 additions and 1 deletions
  1. 2 1
      dtool/src/interrogate/interrogateBuilder.cxx

+ 2 - 1
dtool/src/interrogate/interrogateBuilder.cxx

@@ -1389,7 +1389,8 @@ scan_element(CPPInstance *element, CPPStructType *struct_type,
     // We can only generate a getter and a setter if we can talk about the
     // We can only generate a getter and a setter if we can talk about the
     // type it is.
     // type it is.
 
 
-    if (parameter_type->as_struct_type() != nullptr) {
+    if (parameter_type->as_struct_type() != nullptr &&
+        !parameter_type->is_trivial()) {
       // Wrap the type in a const reference.
       // Wrap the type in a const reference.
       parameter_type = TypeManager::wrap_const_reference(parameter_type);
       parameter_type = TypeManager::wrap_const_reference(parameter_type);
     }
     }