Problem with Packaged plugin... its ignoring me

I recently finished an engine plugin I have been working on. It works perfectly in editor. however, after extensive amounts of effort, I finally got it to package in a build… but it does not run properly.

There seems to be an issue where a thread I launch doesnt launch with the packaged version. I’m not sure why. At least its not crashing I guess.

I have the following in my log to trace:

[2014.08.07-20.23.25:208][  0]Nebula: Nebula Audio Analysis Startup Module called.

[2014.08.07-20.23.25:526][  0]LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_bbc_0///////STATCAT_Advanced//// old //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2278_0///////STATCAT_Advanced////
[2014.08.07-20.23.25:526][  0]LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_150c_0///////STATCAT_Advanced//// old //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2278_0///////STATCAT_Advanced////
[2014.08.07-20.23.25:527][  0]LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2498_0///////STATCAT_Advanced//// old //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2278_0///////STATCAT_Advanced////
[2014.08.07-20.23.25:528][  0]LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_15f0_0///////STATCAT_Advanced//// old //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2278_0///////STATCAT_Advanced////
[2014.08.07-20.23.25:529][  0]LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_137c_0///////STATCAT_Advanced//// old //STATGROUP_Threads//Nebula Audio Analysis Worker///Thread_2278_0///////STATCAT_Advanced////

[2014.08.07-20.23.34:721][280]LogModuleManager: Shutting down and abandoning module NebulaAudioAnalysisPlugin (34)
[2014.08.07-20.23.34:721][280]Nebula: Nebula Audio Analysis Shut down Module called.

My thread start line looks like this in the constructor of my main plugin class.

UpdateThread = FRunnableThread::Create(this, TEXT("Nebula Audio Analysis Worker"), 0, TPri_Normal); 

suggestions?

From where exactly are you creating your thread? The module’s StartupModule function? Also, can you paste the contents of your .uplugin file? Thanks!

Thx for the quick reply.

my startup module is just a log message so I know it was called.

void FNebulaAudioAnalysisPlugin::StartupModule()
{
	UE_LOG(Nebula, Log, TEXT("Nebula Audio Analysis Startup Module called."));
}

my initialization is a class created via blueprints.
the constructor looks like this:

URealTimeNebulaAudioAnalyzer::URealTimeNebulaAudioAnalyzer(const FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{

<bunch of bools and floats and stuff that has no relevance to this>

UE_LOG(Nebula, Log, TEXT("Nebula Audio Analysis - Launching Update Thread."));

	//now launch the actual Audio analysis on a new thread.
	UpdateThread = FRunnableThread::Create(this, TEXT("Nebula Audio Analysis Worker"), 0, TPri_Normal); 
}

… and I have another log message in the Init(), Run(), Stop() functions for the thread and inside the actual logic in my update that I was looking for to ensure it was running. but… what I posted above were the only lines in the log with the word “Nebula” in it.

NebulaAudioAnalysis.uplugin:

{
    "FileVersion" : 3,
	
    "FriendlyName" : "Nebula Audio Analysis Plugin",
    "Version" : 1,
    "VersionName": "1.0",
    "EngineVersion" : "4.2.0",
    "Description" : "Analyses Audio and produces Dynamic Information to manipulate world content",
    "Category" : "Audio.Visualizations",
    "CreatedBy" : "Danny Bernal",
    "CreatedByURL" : "http://betweencode.com",
    
	"Modules" :
    [
        {
            "Name" : "NebulaAudioAnalysisPlugin",
            "Type" : "Runtime"
        } 
    ]
}

I think that plugins are no longer enabled by default. Try adding the following line to your .uplugin file settings:

"EnabledByDefault" : true

Also, from your pasted code it looks like you’re creating the thread from the class constructor. This in itself is not a problem - I just want to make sure you understand the implications of it. Every time an instance of your class is created, it will also create a thread. It is important to know that the UObject system always creates at least one instance of every loaded class - the so called Class Default Object, which is used to cache off the class default settings that are copied into other instances. This means that you will always have at least one of these threads running.

Depending on what you’re trying to achieve, this may or may not be what you want. If you want to start the thread on demand, you may consider a blueprint function on your class and call that from, say, some level blueprint’s event.

I added that line, and there was no difference at all. Same behavior.
Runs fine in editor, but does not load up at all in packaged build.

also in case it matters, in my /Config/DefaultEngine.ini I have:

[Plugins]
 +EnabledPlugins=NebulaAudioAnalysis

Also, thanks for pointing out the constructor issue. While I totally failed to realize that, I don’t think it should be a performance issue, I have 4 “media player” objects and the update thread on each object sleeps for 100ms intervals until a sound is set for playback. This happens when a player touches them. Once set, only the thread for the playing game object should fire up and actually work on the song file given. I haven’t had a chance to test multiple song files simultaneously yet.

The reason I mention how it runs is because I took a look at the output log in the editor now and just saw 7 threads start up when I clicked “simulate” … and 8 threads Stop when I hit stop. then 1 of them starts back up…
I’m guessing the one starting back up is that class default object, but why do I have 7 of these running when I only have 4 players in my level?

my best guess is that there is a editor instance, and a game instance of each of these? but the count is still off. 4 in the editor, 4 in the game, and 1 for default doesnt add up. I was expecting 5 at most. could this have anything to do with the fact its not loading in the packaged builds? my spider sense says no, but I want to leave no assumptions out.

This may be going off topic, but I’m going to investigate the performance issues so many locks could be having on the engine since I don’t have more than 45fps currently. I had thought it was some of the objects I was making. Is there a good way to test this? Should I start a new question?

[edit] holy smokes. I just realized the name of the plugin doesnt match that line in my defaultengine.ini. how the hell did i miss that?!? … let me fix that and try this again…

nope. no difference. same issue even after a full rebuild. I have no idea why it wont load the plugin for a packaged build.

is there an example of anyone using a thread in a plugin?

Is there any possibility that making a thread from plugin code could not work?

I’ve made threads but not ever from a plugin :slight_smile:

Great to hear from you Gerke!

Rama

well, I would think its not an issue with the thread itself, because this line would have run (or at least I assume it should):

UE_LOG(Nebula, Log, TEXT("Nebula Audio Analysis - Launching Update Thread."));

Rather, my constructor for the class is not called at all. It is the constructor that creates the thread.

Here is the odd part…
my plugin creates a structure that contains a whole bunch of analysis result data. A blueprint function returns a copy of this struct so that game objects can apply the data. I find it odd that the game seems aware of and able to process the structure but not able to construct or even attempt to construct the class that creates / populates the structure. Of course, the data is all default 0 data. It tells me that the game is aware of the inner guts of the plugin though. Or at least that’s what I want to assume.

Update:

So, I decided to move all of my thread making logic to the function that sets or removes the audio file to analyze. That way, no threads are created in the constructor, and only 1 thread is ever active in my demo room ( just in case) once the song starts playing. I verified this by assigning each object a unique incrementing ID at construction and edited the log messages for every action I had. There are 4 players in the demo room.

The result: The threads are running now, but no practical difference… Everything works amazingly well in the editor, but no usable results in the packaged build.
At least it appears to be running now, but I don’t understand why the game objects don’t get the right data…

Log:
http://pastebin.com/2xpgSJM3

I honestly have no idea what I should be looking for.

Edit: I decided to include a screenshot in case anyone is wondering what I see.
The new behavior seems to be that it understands that there will be data and creates my game objects in the proper array size etc, but all data must be zeros under the hood. earlier before I moved the threads to the new function, this was an empty display,

so in a strange sort of way, I guess its “technically” working now… its just not working right. I’m now wondering what is wrong with the audio data in the packaged build vs in the editor.

I discovered that I could build packages in developer mode (not sure how I missed that). went ahead and attached the debugger and realized its now failing this line when I attempt to read audio data:

if (AudioSample->RawData.GetBulkDataSize() > 0)

I peeked at SoundWave.h and the RawData is not inside a WITH_EDITORONLY_DATA macro.

poking inside Soundwave.cpp I notice:

// remove bulk data if no AudioDevice is used and no sounds were initialized else if( IsRunningGame() ) { RawData.RemoveBulkData(); }

So if I can figure out which buffer i’m actually supposed to be reading, I should be fine…

as far as the original issue goes though, It seems a thread created in the constructor was giving me some issues. it was never actually loading up and not allowing data to be processed. I have no idea why. All of the log messages in my second log post where I modified the thread creation logic were in my original code as well, they just didn’t display an ID number.

although the original issue went away, the reason is not clear to me. should I close this thread? Or should I let it turn into an audio buffer discussion since im not yet sure where to query the data from when the game is running?

I am getting these similar errors from the threads I run in my project.
I have been using version 4.0 of the engine for a long time, and just a few days ago upgraded my project to 4.4.
I use the threads to create voxel chunks and build a mesh from these chunks. This all works when my project was using 4.0. But with 4.4 im also getting this similar error even tho I havent implemented my code as a plugin:

LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//VoxelGenerationThread///Thread_1c84_0///////STATCAT_Advanced//// old //STATGROUP_Threads//VoxelGenerationThread///Thread_1fac_0///////STATCAT_Advanced////

I have implemented my threads according to Rama’s tutorial on multi threading in UE4. I dont get any of the PlayerController->ClientMessage() outputs that I used to, nor does any data seem to leave the threads at all. In the Profiler I can see that it atleast looks like threads are being launched, as the thread count rises with data preview on.