开发者

EXC_BAD_ACCESS "Office for Mac 2011" Excel macros MicrosoftOleautomation debug cause

开发者 https://www.devze.com 2023-04-11 12:47 出处:网络
I\'m encountering the ubiquitous EXC_BAD_ACCESS error in Microsoft Office for Mac 2011 on OSX 10.7 (Lion). Latest office update installed too (14.3 I believe it was)

I'm encountering the ubiquitous EXC_BAD_ACCESS error in Microsoft Office for Mac 2011 on OSX 10.7 (Lion). Latest office update installed too (14.3 I believe it was)

I'm running a (rather large) macro ... Porting it from PC Office.

The error is happening when adding an element to a collection. Nothing fancy and doing it a zillion other places as well without a problem. (And haven't modified it from the working PC version).

So, while that may be the point of the error, I suspect it has to do with memory of the collection - eg, perhaps it's doing a realloc behind the scenes during this particular insert.

In particular, it's inserting the 2nd element into the collection. No user defined type. Nothing special. Adding a string element. Data being inserted is kosher. The key ID is unique. Bread and butter collection use.

Another possible suspect might be variable scope(???) ... Ie, i开发者_JS百科t might be using a similarly named variable from another sub-routine or something wacky.

Or possibly the temporary string used in the sub-routine is the nominal culprit?

If I comment this line out, the rest of the macro runs okay (aside from the glitch of the missing data from the container ... Which can be empty in normal operation so that's handled okay)

I'm seeking suggestions on how to go about tracking down the issue. And tips towards resolving it.

Is the memory page 64k on mac like it is on PC?

Could it be physical ram / virtual memory / swapping? (Seems too consistent to be system os related)

Perhaps excel has a memory limit cap for macros?

How might I utilize the core dump on the exception to trace the problem?

(Experienced programmer, just unfamiliar with OSX ... And missing all my PC dev tools sigh)


Resolved.

It wasn't the collection.

Through some "printf" debuggging, tracked down the issue. Or, at least, found a solution.

The following is somewhat speculative on what was happening.

Earlier a variant array was created, populated, and passed to a subroutine ...

Dim nameList(50) As Variant
... populated ...
Call SomeSub(nameList)
...
sub SomeSub(nameList)

In the Sub, the variant array was then iterated using a "For Each" loop (which crashed)

For outerLoopIndex=0 To 100

    Dim currName
    For Each currName In nameList
        If testName Like currName Then
            addToBucket = True
            Exit For ' skip any others since found a site of interest
        End If
    Next currName

Next outerLoopIndex

It worked correctly on the first pass of the outer loop. However, data becomes corrupted such that, on the second pass through the outer loop, the EXC_BAD_ACCESS crash occurred.

The "fix" was to explicitly declare as Variant:

    Dim currName As Variant
    For Each currName In nameList
        ... 

Perhaps this will help others running into similar issues. Try explicitly declaring variables. Mac Excel seems to be more sensitive to such things. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消