gpvigano / M2MqttUnity

M2MQTT for Unity
MIT License
155 stars 59 forks source link

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

Open dariusjulian opened 1 year ago

dariusjulian commented 1 year ago

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.

tsantor commented 11 months ago

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>();
    }

}