# Desktop App Crashes Runtime Error Bad Objective-C cast

**URL:** <https://forum.xojo.com/t/desktop-app-crashes-runtime-error-bad-objective-c-cast/67942>\
**Category:** macOS\
**Created:** [January 12, 2022, 2:34pm UTC](https://forum.xojo.com/t/desktop-app-crashes-runtime-error-bad-objective-c-cast/67942 "2022-01-12T14:34:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Bader](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_bader/32/1412_2.png) [@Christian\_Bader](https://forum.xojo.com/u/Christian_Bader)\
**Post date:** [January 12, 2022, 2:34pm UTC](https://forum.xojo.com/t/desktop-app-crashes-runtime-error-bad-objective-c-cast/67942/1 "2022-01-12T14:34:16Z")

</div>

Heya,

I have a small problem. I am running a Desktop App which crashes spontaneously on macOS.

Most of the time I don’t even get an error. Sometimes I get a Runtime Error like:

```auto
Runtime Error
Location Common/Cocoa/ObjCObject.h:135
Condition: !"Bad Objective-C cast"

```

This happens in an 8 Hour Use time around 3-8 Times a Day which is kinda often.  
We tried to find reproducible Steps but it happens always in Different Scenarios. The only thing shared in the Scenarios is that I create controls on the fly and embed them. So anyone has an idea if it’s probably this?

For ex:

```auto
Dim cc as new conProductButton //container ctrl
cc.EmbedWithin(con,posx*cc.Width,posy*cc.Height,cc.Width-15,cc.Height)

```

closing controls like:

```auto
if curView <> nil then
  if curView isA conButtons then
    conButtons(curView).Close
  end if
end if

```

If anyone has an Idea what exactly could cause the bad objective-c cast I would be happy.

Thanks in advance.

Christian

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [January 13, 2022, 12:58am UTC](https://forum.xojo.com/t/desktop-app-crashes-runtime-error-bad-objective-c-cast/67942/2 "2022-01-13T00:58:13Z")

</div>

I would suggest you contact Xojo support as I don’t see anything that could cause this and I think they need to see it crash from their IDE so that they can see what’s going on behind the scenes.

I use code like this all the time.
