5CG893

This page contains details of a discussion with Mathworks over a particular issue with BRAHMS/Matlab integration.

Summary

The warning cannot be suppressed, but is gone in R2007B. Calls to engOpen(NULL), engClose() immediately followed by another engOpen() will get a NULL back from the second call. Inserting sufficient wait will solve the problem:
engOpen()
engClose()
Sleep(...)
engOpen()
Mathworks agree that this is a bug, and have filed it as such. Note that engOpenSingleUse() is unaffected.

Discussion

...i am getting the following warning:
Warning: Handle array initialization failed.
Warning: MCOS initialization failed.
produced on stdout when calling engOpen(). this sometimes seems to be associated with getting a NULL back from that call, and sometimes not. a) what are the reasons for getting a NULL back from engOpen()? the docs say "NULL if the open fails" which i would usually be ok with. but i'm getting NULL or not arbitrarily. rapid repeated calls to engOpen(), engClose() may play a role? b) what do the warnings mean, and can I suppress them?
...The warning usually mean the MATLAB class definitions and graphics handling did not initialise properly. I have yet to reproduce these errors, or the arbitrary NULL problem, could you clarify exactly what you are doing to get these error messages?
specifically, i compile the attached file (checkengine.cpp from R987) using the cl command line listed therein. and the output i get is
d:\temp\brahms\trunk\matlab\wrapper>cl checkengine.cpp -EHsc libeng.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

checkengine.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:checkengine.exe
checkengine.obj
libeng.lib

d:\temp\brahms\trunk\matlab\wrapper>checkengine.exe
open 0

ans =

d:\shared\library


OK! close 0
open 1
NULL
open 2
Warning: Handle array initialization failed.
Warning: MCOS initialization failed.

ans =

d:\shared\library


OK! close 2
open 3
Warning: Handle array initialization failed.
Warning: MCOS initialization failed.
NULL
open 4
Warning: Handle array initialization failed.
Warning: MCOS initialization failed.

ans =

d:\shared\library


OK! close 4

d:\temp\brahms\trunk\matlab\wrapper>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]
platform is a Dell X300 Windows XP Pro 32-bit with...
>> ver
-------------------------------------------------------------------------------------
MATLAB Version 7.0.0.19920 (R14)
MATLAB License Number: 0
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service
Pack 2)
Java VM Version: Java 1.4.2 with Sun Microsystems Inc. Java HotSpot(TM)
Client VM
-------------------------------------------------------------------------------------
MATLAB                                    Version 7.0        (R14)
Simulink                                  Version 6.0        (R14)
Image Processing Toolbox                  Version 4.2        (R14)
Optimization Toolbox                      Version 3.0        (R14)
Signal Processing Toolbox                 Version 6.2        (R14)
Statistics Toolbox                        Version 5.0        (R14)
Symbolic Math Toolbox                     Version 3.1        (R14)
as you can see, this works fine on the first call. on the second, i get NULL returned. on the third it works. on the fourth, failure. on the fifth it works. separating this into two things. the NULL issue first. some timing info... the first call gets to engOpen(). we wait a little while the engine opens. then it proceeds and everything is good and it closes. the second call calls engOpen and (this is the crux i think) hangs for a few seconds, longer than i would normally wait for matlab to start, then reports failure (NULL returned). i suspect, then, that the second engOpen() call is being made whilst clean-up is not complete after the first, though i don't know how your internals work obviously, and i am no COM guru by any means. adding evidence to this is that the third call works fine: on this call, we have already wiated 3 or 4 seconds in the second call's engOpen() (which failed), so by the time we make the engOpen() call in the third iteration there has been plenty of time to clean up the state. this is my interpretation. as you can see, the pattern cotinues... 3rd call works, 4th call hangs a few seconds then fails, fifth call works. i imagine this would go on, it's certainly very reliable when i try again and again. the warning issue second: does not seem to be reliable. the warnings are peppered all about. however, i have never seen them occur on the first call, so perhaps this is also a "state not quite ready" type issue? if i use engOpenSingleUse(), no problems with NULL pointers, but i still get the warnings, and nowi get them reliably on every call other than the first. conspicuously, the matlab processes from earlier loops tend to be still closing as later ones are starting, perhaps adding further weight to the idea that it's a stateful issue.
I tried your code on two versions of MATLAB, R14 which you are using and R2007b which is the latest version. With R14, I get exactly the same results as you. The NULL error that occurs with engOpen() exists in both R14 and R2007b. It is resolved by putting a sufficiently large pause between iterations. This supports what you suspect, and I would agree as well. I will forward this as a bug report to our developers. I also get the two warning messages in R14, but it is fixed by R2007b. The engine still has full functionality, although I haven't yet found a way to suppress the messages.