M2MqttUnity icon indicating copy to clipboard operation
M2MqttUnity copied to clipboard

NullReferenceException: Object reference not set to an instance of an object

Open dariusjulian opened this issue 1 year ago • 1 comments

I'm hoping I can get some help with an issue I'm having. After running a build for 2-3 hours with no interactivity, I start getting this error and the app no longer receives any data from MQTT.

NullReferenceException: Object reference not set to an instance of an object
  at M2MqttUnity.M2MqttUnityClient.ProcessMqttMessageBackgroundQueue () [0x00016] in <a142f2b118d44b049fd51176acc445ad>:0 
  at M2MqttUnity.M2MqttUnityClient.ProcessMqttEvents () [0x00012] in <a142f2b118d44b049fd51176acc445ad>:0 
  at M2MqttUnity.M2MqttUnityClient.Update () [0x00000] in <a142f2b118d44b049fd51176acc445ad>:0 
  at MyM2MqttUnityScript.Update () [0x00000] in <a142f2b118d44b049fd51176acc445ad>:0 

Any one might be of help as to why this might be happening?

Thanks you in advance.

dariusjulian avatar Oct 06 '23 19:10 dariusjulian

We're running into this same issue. It seems that ProcessMqttMessageBackgroundQueue is called twice and in the second call it seems for some reason backMessageQueue is null and clear fails?

Our temp workaround is:

private void ProcessMqttMessageBackgroundQueue()
{
    try {
        foreach (MqttMsgPublishEventArgs msg in backMessageQueue) {
            DecodeMessage(msg.Topic, msg.Message);
        }
        backMessageQueue.Clear();
    }
    catch {
        DebugLogger.Log("WARNING: BackMessageQueue is null, reinstantiating the list", DebugErrorTypeEnum.error);
        backMessageQueue = new List<MqttMsgPublishEventArgs>();
    }
    
}

tsantor avatar Dec 01 '23 19:12 tsantor