godotengine / godotengine/godot-cpp
[3.4.2] register_method does not accept arguments passed by reference
- Lingua principale
- C++
- Stelle
- 2.7k
- Fork
- 810
- Merge medio
- 1g 3h
- PR unite (30g)
- 8
Descrizione
Let suppose a member method like this:
```
void Foo::bar(godot::String const name);
```
If we want to make it uses for GDNative script, we have to export it:
```
godot::register_method("bar", &Foo::bar);
```
This makes pass the string by copy and this works fine ! But now let pass `name` by reference:
```
void Foo::bar(godot::String const& name);
```
But this reference will produce a warning:
```
...
/home/qq/godot/3.4.2-stable/cpp/include/core/Godot.hpp:163:10: warning: returning reference to temporary [-Wreturn-local-addr]
163 | return a;
| ^
```
And possibly gives a crash. So How to deal: passing C++ reference with register_method ?
PS: register_method and C++ references worked well within Godot modules (C++ code inside the Godot editor code source inside the modules/ folder). I had no warnings.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Esamina core/Godot.hpp intorno alla riga 163 e l’implementazione di register_method, quindi riproduci l’avviso con l’esempio const-reference Foo::bar dell’issue. Determina come vengono gestiti gli argomenti di riferimento registrati e verifica che l’esempio non produca più avvisi né vada in crash; l’issue è completata quando i parametri di riferimento funzionano in sicurezza tramite register_method.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100