OpenCities Map Advanced crashing after opening chart and changing model


This week I found strange behavior in our plugin running on OpenCities Map Advanced 7. I´ve been trying to pinpoint the cause of this behavior and find out why is it happening. However, I got unlucky and decided to ask for some help here.


We are using system hook (NewDesignFile callback) to react properly when opening dgn files. Here we are doing some additional setting of our internal data, so no MDL or other Microstation related calls. Then we want to switch to a specific model (lets call it model A, and the model that is opened automatically with DGN will be model B). We are using simple code snippet:

    DgnModelRefP pDgnModelRef = nullptr;
    StatusInt result = mdlModelRef_createWorkingByName(&pDgnModelRef, mdlDgnFileObj_getMasterFile(), modelName, false, false);

    if (result == SUCCESS && pDgnModelRef != NULL)

This code snippet is very important, I will explain it later.

After that, everything looks fine. The problem is, when I try to switch to my original model B back. I receive an exception/or when not in debug crash, referencing me to the ECObjects6.dll, with callstack full of ustation functions, so i´m kinda unable to tell where the problem arises. 

I´ve tried to reduce the code called by our plugin to minimum, so i would be able to locate what is causing the problem. The thing i found was that, if I dont call the mdlModelRef_activateAndDisplay in code snippet I´ve attached before, everything works fine. Even at the later stage, when I´m calling mdlModelRef_activateAndDisplay manually from other parts of code, everything is fine. It looks like it is just this time, when opening dgn file. But i need to call it that way to change the model at startup. 

At first i thought its related to model references, but I made simple example with models with 0 references, but didnt help. 

Do you guys have any ideas what can be causing this problem? 

Stack dump: 

Stack dump:
Exception: 0xc0000005 @ 0x384eeaf2
 0: 000000477adfbbd0 00007ffa0a56e258 000001e3e3f4b2e0 000001e3e3f4b2e0 00000000ffffffff 0000000000000000 Bentley::ECN::ECSchema::CreateClass+0x22 
 1: 000000477adfbd00 00007ffa0a579530 000001e3fe6ac270 000001e300000000 000001e3ee16ce70 0000000000000000 xfmViewLabelDef_setTrimTargetGeometryToView+0xe694 
 2: 000000477adfbd70 00007ffa0a56d2e0 000001e3cd5082b0 00007ffa0a77d430 000000477adfbde0 000001e3ee16ce70 GsxBaseFeatureHandler::IsDynamicScoredFeature+0x64e0 
 3: 000000477adfbda0 00007ffa0a457a0f 00007ffa0a77d430 000001e3cd5082b0 0000000000000001 000001e40396f080 xfmViewLabelDef_setTrimTargetGeometryToView+0xd71c 
 4: 000000477adfbe10 00007ffa0a52b1ee 000001e3cd5082b0 000001e3fccba7d0 000001e40396f080 0000000000000001 xfmCore_endXfmUndoGroup+0x13b 
 5: 000000477adfbed0 00007ffa0a528bbb 000000477adfc048 00007ffa0a77d430 00007ffa0a604958 000001e3a38b0bf0 XfmV2UuidFeatureInstance::AddFeatureElement+0xdca 
 6: 000000477adfbfb0 00007ffa0a52ca08 0000000000000000 000001e3fccba7d0 00007ffa0a77d430 000001e3c1928530 XfmV2UuidFeatureInstance::AddChangedElementsToRootFeatureChange+0x5bf 
 7: 000000477adfc4c0 00007ffa0a52ab06 000001e3c1928530 000001e3d880e110 000000477adfc5a0 0000000000000000 XfmV2UuidFeatureInstance::AddToXfmGroup+0x7f0 
 8: 000000477adfc560 00007ffa0a52aea4 000001e3d880e110 000001e3fccba7d0 000001e3fccba700 000001e3d880e110 XfmV2UuidFeatureInstance::AddFeatureElement+0x6e2 
 9: 000000477adfc5d0 00007ffa0a527c18 000001e3d880e101 000000477adfc6e0 000001e3fccba7d0 00000000baadf00d XfmV2UuidFeatureInstance::AddFeatureElement+0xa80 
10: 000000477adfccb0 00007ffa0a54402a 000001e3d880e110 000000006042ca22 0000000000000000 0000000000000000 XfmFeatureIterator::`default constructor closure'+0x7f0 
11: 000000477adfccf0 00007ffa0a45089e 000001e3d880e110 0000000000000000 00000000fffffffd 0000000000000062 xfmSessionFeaturesList_addByModelRef+0x2a 
12: 000000477adfd370 00007ffa0a452c07 00007ffa0a726658 000001e3fe12b800 0000000000000000 00007ffa66e040f8 XfmCore::LoadCaches+0x61a 
13: 000000477adfd3a0 00000000604a23d6 000001e3ee231870 000001e3ca7f3ab0 000001e3fe12b800 0000000060f1dd30 XfmCore::_CreateVBScriptControl+0x25f 
14: 000000477adfd3f0 00000000604a675c 0000000060f1dd30 000001e3d8805470 000001e3ec5d8b50 000001e3ee1c6010 Bentley::MstnPlatform::RightsTokenManager::SetToken+0xd76 
15: 000000477adfd430 00000000604a6872 000001e3d880e110 000001e3ee1c6010 000001e3d880e110 000001e3da458df0 Bentley::MstnPlatform::ISessionMgr::MakeActiveModel+0x6c 
16: 000000477adfd460 0000000060a7ff7b 0000000000000006 0000000000000008 000001e3d880e110 0000000060a7fd06 Bentley::MstnPlatform::ISessionMgr::MakeRootModel+0x102 
17: 000000477adfd4c0 00007ffa0126df51 000001e3da45a7f0 0000000000000000 000001e3fe81dee0 0000000000000001 Bentley::DgnPlatform::ViewInfo::GetFrustumFromReference+0x126b 
18: 000000477adfd520 0000000060a8168e 000001e3fe2fb2b8 000001e3da45a7f0 000001e3fe2fb4b8 000001e3d634a700 Bentley::DgnPlatform::ViewGroupCollection::MakeActive+0xc1 
19: 000000477adfd560 000000006083b867 000000477adfd650 000001e3da458df0 0000000000000001 000001e3fe81dee0 mdlViewGroup_applyByName+0x6e 
20: 000000477adfd590 00000000606b5aa3 000001e3fe2fb4b8 000001e3c76279b0 0000000000000001 000000477adfd650 inputmanager_main+0x10e47 
21: 000000477adfd610 00000000606d3bad 000001e3fe81dee0 000001e3e603a140 000001e3ec5d7cf0 0000000000000001 mdlDialog_hookItemCall+0x133 
22: 000000477adfd770 00000000606ab9f3 0000000000000000 000001e3e7e10fa0 000001e3d634d560 000001e3e603a140 mdlDialog_rItemStateSet+0xfd 
23: 000000477adfd7a0 0000000060703b5f 000001e3fe81dee0 000000477adfd901 000001e3e603a140 00007ffa66e040f8 mdlDialog_itemSetStateMaybe+0x73 
24: 000000477adfd890 00000000607036bf 000001e3e603a140 0000000000000001 000000477adfd9a0 000000477adfdb70 mdlDialog_colorPickerSetInfo+0x15ff 
25: 000000477adfdae0 00000000606ab414 000000477adfdb00 0000000000000000 000001e300000003 00000000606ab200 mdlDialog_colorPickerSetInfo+0x115f 
26: 000000477adfdb30 000000006078a30c 000001e3ec5d7cf0 000000006070b6d0 000001e3ec5d7cf0 0000000000000016 mdlDialog_itemMessageSend+0x114 
27: 000000477adfdc50 00000000606ab414 000001e3fe81dee0 ffffffe8000000e0 000001e3e603a101 000000477adfdd50 mdlDialog_toggleIconSetIconColors+0x267c 
28: 000000477adfdca0 00000000606a3800 000001e3ec5d7cf0 000000006078fb50 00000000610919c0 000000477adfdf78 mdlDialog_itemMessageSend+0x114 
29: 000000477adfdce0 00000000606a2219 000001e3df811840 000001e3e603a140 000000477adfdf00 000000477adfe010 mdlVisualStyle_isThemeActive+0x3290 
30: 000000477adfde00 00000000606a1779 000001e3e603a140 000000477adfdf10 0000000000000001 00000000610919c0 mdlVisualStyle_isThemeActive+0x1ca9 
31: 000000477adfdf50 00000000606a5bca 000001e3e603a140 000001e3e603a140 000000477adfe010 000001e3df811840 mdlVisualStyle_isThemeActive+0x1209 
32: 000000477adfdf80 00000000609e9dc2 000000477adfe010 000001e3e603a140 000001e3fdc94760 00000000608dd3ca mdlVisualStyle_isThemeActive+0x565a 
33: 000000477adfdfd0 00000000609df23d 000000477adfe0e0 000000477adfea20 0000000000000000 0000000000000001 mdlSystem_keyinQueue+0x202 
34: 000000477adfe9c0 00000000609e2795 000000477adfea20 0000000000000001 000001e3b545a168 000001e3ef9f8cd0 priorityGui_initialize+0x8bd 
35: 000000477adfe9f0 00000000608795a4 000000006087ad20 000000006087ad20 0000000000000000 0000000000000000 mdlInput_processQueuedInput+0x25 
36: 000000477adfea30 000000006091cadc cfdbc54ee12a0000 0000000000000009 0000000000000009 0000000000000009 mdlInput_handleModifierTransition+0x124 
37: 000000477adfead0 000000006091ed59 000001e3ef9f8cd0 00007ffa66e040f8 000001e3efcaac48 000001e3ef9f8cd0 Bentley::MstnPlatform::ISessionMgr::SetSnapsPopupGroupKeyin+0xd9c 
38: 000000477adfeb60 00000000609a4fc9 000001e3ec5c3f90 000000000000606c 00007ffa66e040f8 000001e3e9fe4700 mdlSystem_recordUserActivity+0x429 
39: 000000477adfeda0 00007ff6887b5ffc 0000000040013f44 00007ff6887b0000 000001e3e9fea240 0000000000000001 win32Intface_winMain+0x169 
40: 000000477adfef20 00007ff6887b5ca7 0000000000000002 000001e3e9fe4700 0000000000000001 000000477adff400 <nosymbol> 
41: 000000477adfef60 00007ff6887b19ee 0000000000000001 000000477adff050 000001e3ea032dd0 000000477adff201 <nosymbol> 
42: 000000477adfefa0 00007ff9feb52178 000000477adff178 00007ffa43ef5f60 00007ffa4409c660 ffffffffffe5004a <nosymbol> 
43: 000000477adfefa8 000000477adff178 00007ffa43ef5f60 00007ffa4409c660 ffffffffffe5004a 00001f5fcd2d537b <nosymbol> 
44: 000000477adfefb0 00007ffa43ef5f60 00007ffa4409c660 ffffffffffe5004a 00001f5fcd2d537b 00007ffa5e87a9f0 <nosymbol> 
45: 000000477adfefb8 00007ffa4409c660 ffffffffffe5004a 00001f5fcd2d537b 00007ffa5e87a9f0 000000477adff248 <nosymbol> 
46: 000000477adfefc0 ffffffffffe5004a 00001f5fcd2d537b 00007ffa5e87a9f0 000000477adff248 00007ff9fea46c20 <nosymbol> 
47: 000000477adfefc8 00001f5fcd2d537b 00007ffa5e87a9f0 000000477adff248 00007ff9fea46c20 00007ff9fea46c20 <nosymbol> 
48: 000000477adfefd0 00007ffa5e87a9f0 000000477adff248 00007ff9fea46c20 00007ff9fea46c20 000000477adfefb0 <nosymbol> 
49: 000000477adfefd8 000000477adff248 00007ff9fea46c20 00007ff9fea46c20 000000477adfefb0 00007ff9feb52178 LegacyNGenTryEnumerateFusionCache+0xe4350 
50: 000000477adfefe0 00007ff9fea46c20 00007ff9fea46c20 000000477adfefb0 00007ff9feb52178 000000477adff050 <nosymbol> 
51: 000000477adfefe8 00007ff9fea46c20 000000477adfefb0 00007ff9feb52178 000000477adff050 00007ff9fea46c20 <nosymbol> 
52: 000000477adfeff0 000000477adfefb0 00007ff9feb52178 000000477adff050 00007ff9fea46c20 000000477adff178 <nosymbol> 
53: 000000477adfeff8 00007ff9feb52178 000000477adff050 00007ff9fea46c20 000000477adff178 000000477adff148 <nosymbol> 
54: 000000477adff000 000000477adff050 00007ff9fea46c20 000000477adff178 000000477adff148 000000477adff248 <nosymbol> 
55: 000000477adff008 00007ff9fea46c20 000000477adff178 000000477adff148 000000477adff248 000000477adff400 <nosymbol> 
56: 000000477adff010 000000477adff178 000000477adff148 000000477adff248 000000477adff400 000000477adff100 <nosymbol> 
57: 000000477adff018 000000477adff148 000000477adff248 000000477adff400 000000477adff100 000000477adff178 <nosymbol> 
58: 000000477adff020 000000477adff248 000000477adff400 000000477adff100 000000477adff178 0000000000000004 <nosymbol> 
59: 000000477adff028 000000477adff400 000000477adff100 000000477adff178 0000000000000004 000000477adff080 <nosymbol> 
60: 000000477adff030 000000477adff100 000000477adff178 0000000000000004 000000477adff080 00007ffa5e0b6913 <nosymbol> 
61: 000000477adff038 000000477adff178 0000000000000004 000000477adff080 00007ffa5e0b6913 00007ffa5e0b7060 <nosymbol> 
62: 000000477adff040 0000000000000004 000000477adff080 00007ffa5e0b6913 00007ffa5e0b7060 00007ff9fea44148 <nosymbol> 
63: 000000477adff048 000000477adff080 00007ffa5e0b6913 00007ffa5e0b7060 00007ff9fea44148 0000000000000000 <nosymbol> 
64: 000000477adff050 00007ffa5e0b6913 00007ffa5e0b7060 00007ff9fea44148 0000000000000000 00007ffa00000000 <nosymbol> 
65: 000000477adff060 00007ff9fea44148 0000000000000000 00007ffa00000000 000000477adff170 000001e3ea032dd0 LogHelp_LogAssert+0x1b93 
66: 000000477adff068 0000000000000000 00007ffa00000000 000000477adff170 000001e3ea032dd0 0000000000000000 <nosymbol> 

Note: I have been opening it in V8I without any problems, even this problem is not existing in V8i. If I delete all elements from the model I want to switch to(mostly text elements), the exception is not happening. But i need them here

Parents Reply
  • Hi Lubo,

    Do you guys have any ideas what can be causing this problem? 

    because it looks like the code works fine in MicroStation, I am thinking about a possibility the problem is in "timing" and that you start your code too early:

    Used SystemFunc_NewDesignFile callback is the right way (even when I would prefer to use ISessionMonitor, but the result will be the same I guess).

    Maybe the problem is that it's called by power platform (aka MicroStation engine), not OpenCities Map application. So, maybe, when opening process is finished and the event is fired, OCM starts to process its content (to build data model based on elements in DGN and active project configuration).

    I treat any modification / context (model or design file) switch immediately after file/model opening as risky operation and bad habit in general, because you never know what other applications listen the same event and rely on it. For sure can be done in strictly controlled environment, where no other 3rd party code is active.

    I do not know whether OCM API offers similar event when not plain DGN, but complete model in active project is loaded successfully. Maybe or can help there?

    What you can try is to wait until MicroStation is in idle state. It's not documented in C++ API (probably because of omission), but exported from dll, so can be used. See this discussion for some details.

    So: When new file event (model is loaded) is fired, register for idle event. When it happen, unregister from this event (or ignore it using early escape, because called frequently), do what is necessary. I guess it should work, because idle event means MicroStation has nothing more to do.

    With regards,


  • I was thinking the same way! At first, I thought that newDesignFile callback function is a safe place, to do stuff like switch models etc. (because I read somewhere that it is called after everything is initialised - but that was probably meant for base Microstation API). At first I didn´t think OpenCities would affect that in this manner. What I tried to do was that after I opened DGN file, I activated my CommandFilterFunction. After I received first event I changed the model. And suddenly everything was working fine. But I didn´t think about listening for IDLE state, good tip! The thing about OCM API event however, I´m not sure if I want to go this way, as I would like my plugin to work same both on pure Microstation application or OCM applications.

  • because I read somewhere that it is called after everything is initialised

    I think it's not written anywhere using this formulation ;-)

    The most precise description I am aware of is Session Manager description (which is where you should start, now with old MDL functions), and based on that, in my opinion, MicroStation cannot ensure everything is initialized. At least because of loading DNGAPPs, that can start own activities automatically.

    At first I didn´t think OpenCities would affect that in this manner.

    OCM (and any other product like ORD or OBD) are - from power platform perspective - standard 3rd party applications. Maybe they use internal APIs we do not know about, but it's not magic, they have to follow the same rules and share the same application and data context.

    After I received first event I changed the model.

    I do not know the context, but as I wrote earlier, to force to change a model looks like intrusive workflow (and not robust defensive one). When the workflow is not well design, the code rarely can help to do the system really robust.

    I think also whether there is a way to open the file with the right model directly, and do not wait until "some model" is opened and everything is loaded and initialized. But it's beyond my current knowledge.

    as I would like my plugin to work same both on pure Microstation application or OCM applications.

    In my opinion such wish is logical and make sense, but should not be a precondition, but a result of analysis. Sometimes to use product specific API allows to simplify the code for MicroStation a lot (e.g. to remove checks and if/else conditions during the runtime). But when it's possible, to have one code base only is always an advantage ;-)