I recently received a crash log with the following call stack:
> System.DivideByZeroException: Attempted to divide by zero. at
> System.Math.Log(Double a, Double newBase)
But, from what I can tell from the docs, this exception shouldn't be thrown and I've tried all sorts of inputs in a test program and haven't been able to reproduce this exception. Also, the code calling this function has a limited range of inputs so I think the input values are ok.
I'm wondering if this might be the result of a bad plugin (my program hosts plugins typically written in C++) or some other piece of code leaving a floating point error on the FPU?
Any thoughts on how to prevent or at least protect myself from this?
Update to answer some questions in the comments:
- This is happening in .NET 4 Client Profile
- The app is built in Release mode
- I don't have access to the input values that cause the exception
- I can't really disable the plugins - this is a music app hosting VST plugins.
- The exception is extremely rare - I've see it just twice with thousands of users running the app everyday so trying this in vs out of app context won't really help.
- The newBase parameter is always 10.0 on the call stack where the exception was reported - so the non-epsilon comparison to 1.0 shouldn't be the issue.
Update 2: turns out this customer could reproduce the problem and found it to be related to licensing of one of his plugins. Once the licensing issue was fixed the issue went away. That's a way too mystical for my liking but at this stage I'm just glad he's got a fix. To quote the customer it "eventually crashed every host in different ways".