Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[4.8p2] compile fails on class with non-default constructible member

My plugin fails to compile the "MyPluginName.generated.cpp" file.

In that file, the DEFINE_VTABLE_PTR_HELPER_CTOR(TClass) macro (related to hot relaods ?) adds: TClass::TClass(FVTableHelper& Helper) : Super(Helper) {};

No class member is initialized, then:

  • members of a native type (int, etc.) are not initialized, (not a great idea)

  • members of a type that is not default constructable make the compilation fail

Is there an option to prevent the use of this macro for certain classes ? (or all classes, as it looks quite dangerous...)

Product Version: UE 4.8 Preview
more ▼

asked May 14 '15 at 06:10 PM in C++ Programming

avatar image

51 2 4 11

avatar image jppm May 27 '15 at 03:50 PM

I get this error too. The following code is enough to trigger this. (at github 4.8 tip)

HEADER fail48.h:

 #pragma once
 #include "GameFramework/Actor.h"
 #include "MyActor.generated.h"
 class MemberClass
     MemberClass(int val) : m_val(val) {}
     int m_val;
 class FAIL48_API AMyActor : public AActor

     MemberClass m_member;

SOURCE fail48.cpp:

 #include "fail48.h"
 #include "MyActor.h"
  : Super(),
    m_member(2) // NOTE


In fail48.generated.cpp, the line


Causes the following:

 error C2512: 'MemberClass' : no appropriate default constructor available
avatar image jppm May 27 '15 at 03:57 PM

The offending code is from CoreUObject/Public/UObject/ObjectBase.h:

     TClass::TClass(FVTableHelper& Helper) : Super(Helper) {};

This will never call any other ctor in TClass .

avatar image jppm May 27 '15 at 04:29 PM

Tracing this further, it was implemented as a fix to UE-10111 Hot Reload crash with Scene Component tied to Actor class

avatar image jppm May 27 '15 at 05:31 PM

The macro DEFINE_VTABLE_PTR_HELPER_CTOR is defined when WITH_HOT_RELOAD_CTORS is defined. As a temp workaround, I posted a separate question to find out how to disable WITH_HOT_RELOAD_CTORS .

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

EDIT Jun 15: The 4.8 release notes (way down, in the Core section) say the following about this:

Hot reload uses special empty auto-generated constructors to obtain virtual table pointers from UObjects and to avoid re-constructing subobjects when creating temporary objects after loading the recompiled DLL but before the classes have been regenerated. This implies the requirement that all member variable types are default constructible.

The signature of the new constructor is UMyClass::UMyClass(FVTableHelper& Helper) and it can be manually defined in the header file to initialize all member variables that are not default-constructible

Auto-generation of the new constructors can be disabled by defining WITH_HOT_RELOAD_CTORS macro to 0 and setting [Core.System] UseVTableConstructors to False in BaseEngine.ini.

Note that disabling this feature may result in crashes when performing hot reload.

So it's confirmed - either disable hot reload ctors or add this special ctor to your class members as needed.

The message of the commit which introduced this problem contains indications on how to workaround it:

Commit: 3c450b947746aec52557f1ea4c7546ab3f0204ca

Date: 2015-03-02 11:44:04

UE-10111: Hot Reload crash with Scene Component tied to Actor class

We've changed the way vtable ptr are obtained for UClasses. Right now we use special empty constructor to get it, so we don't have to use normal one which was causing troubles. This special vtable helper constructor is generated automatically for most cases, but sometimes it's not possible (e.g. no default constructor for members types). In such case there is a possibility to override that generated constructor and write a custom one. The signature is UCustomClass::UCustomClass(FVTableHelper& Helper) and it needs to call base class'es constructor with the same parameter. Please do not use these constructors for anything else. There is no guarantee the object will be in correct state after calling this.

You can still disable this functionality if something breaks, just set WITH_HOT_RELOAD_CTORS to 0.

[CL 2466152 by Jaroslaw Palczynski in Main branch]

So if I read the message correctly, my example above would be fixed by adding a ctor to AMyActor:

 class FAIL48_API AMyActor : public AActor
     // adding this ctor fixes the problem:
     AMyActor(FVTableHelper& Helper)
     : Super(Helper),
       m_member(2) // and here you can initialize your members
     MemberClass m_member;

My engine is compiling, so right now I can't confirm that doing this solves the problem.

[EDIT May 28: Just confirmed - adding the constructor fixes it.]

more ▼

answered May 28 '15 at 11:51 AM

avatar image

120 8 93 21

avatar image monsieurgustav May 28 '15 at 07:07 PM

I'm not sure that I like the solution, but it works ! Thanks a lot !

avatar image robert.manuszewski STAFF Jun 03 '15 at 04:44 PM

Also, you could just make sure m_member type supports a default constructor.

avatar image Chrys Jun 14 '15 at 05:27 AM

not every class we want to construct does necessarily want a default constructor or is provided with one. In my case I use a third party library that has no default constructors for a specific reason.

avatar image Chrys Jun 14 '15 at 06:30 AM

I can confirm that adding the constructor mentioned above works for me too in my case.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question