使用VCL样式在TOpenDialog中给出异常/崩溃 [英] Using VCL Styles gives a exception / crash in TOpenDialog

查看:63
本文介绍了使用VCL样式在TOpenDialog中给出异常/崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用启用了VCL样式的简单TOpenDialog时,我遇到崩溃/异常。



如果未启用样式,则对话框当然可以正常工作。问题发生在C ++ Builder 10和10.1 Professional中。



要重现:


  1. 创建使用样式的simpe VCL表单

  2. 向该表单添加TComboBox,TButton和TOpenDialog

  3. 添加以下代码到按钮的OnClick事件

      OpenDialog1-> Execute(); 
    for(int i = 0; i< 100; i ++)
    ComboBox1-> Items-> Add( test text);
    ComboBox1-> ItemIndex = 1;


  4. 运行应用程序,单击按钮并选择一个文件


  5. 对我来说,这会导致异常系统资源不足

此错误可以重现在Windows 7 Enterprise和Windows 8.1 Pro上。
TSaveDialog也有相同的问题。



对我来说,奇怪的是,关于该例外,我在网络上找不到类似的问题。我认为,仅需要VCL样式和TOpenDialog才具有此功能,我希望可以在Web上获得有关此信息的更多信息。这里有一个例外,对于本地VCL样式也没有解决方案:










*编辑2016/05/26 *



Remy Lebeau要求获得MCVE。我试图将所有问题都放入问题中,但为清楚起见,这里是MCVE的摘要:




  • 使用默认设置创建新的VCL项目

  • 将TComboBox,TButton和TOpenDialog拖放到窗体中

  • 将以下代码添加到按钮的OnClick事件中:

      void __fastcall TForm1 :: Button1Click(TObject * Sender)
    {
    OpenDialog1- > Execute();
    for(int i = 0; i< 100; i ++)
    ComboBox1-> Items-> Add(L test text);
    ComboBox1-> ItemIndex = 1; //<-例外在这里
    }


  • 启用VCL样式'在项目选项中选择Smokey Quartz Kamri


  • 运行程序,按按钮,选择任何文件,然后在TOpenDialog中选择OK



在这里,这确实是例外所需要的。



在我看来,对Execute()的调用弄乱了一些内容VCL结构(仅在启用样式的情况下),然后再访问另一个VCL项(在我的情况下为combobox)会导致崩溃。



我现在知道并不是每个一个人有这种崩溃。因此,请原谅我,如果这不是每个人的100%可验证的例子。



但是我和我的同事不是唯一遭受过这次车祸的人(经过测试)



*编辑2016/05/27 *



关于Tom Brunberg的单步请求,该异常发生在WndProc中的某个地方,在通话中地址005459F4的屏幕快照中。



如果我走得更远,我将登陆TCustomCombo.WndProc。之后,由于WndProc中的重复循环,很难继续进行后续操作,似乎无法到达引发异常的最终位置。





*编辑2016/05/27秒*



好的,我设法查明了崩溃的确切位置。在VCL.Graphics中的函数CopyBitmap中。在第一个屏幕截图中,以下行发生异常:



结果:= GDICheck(CreateCompatibleBitmap(ScreenDC,bmWidth,bmHeight))



在第二个屏幕快照中的函数GDICheck()中,在调试器中变量Value为零,因此依次调用了函数GDIError。在那里,ErrorCode也为零,这导致调用OutOfResources。



希望这有助于进一步缩小范围。










*编辑2016/07/19 *



由于这里似乎没有人遇到这个问题,因此我们尝试了另一种尝试:
该公司的一位同事做了一个新的C ++ Builder 10.1 Berlin安装,用英语(认为也许是德国IDE的元凶),
和安装后的第一件事,重新创建了StylesCrashTest App。结果是一样的,选择文件并在对话框中单击打开后,它立即崩溃。



我已将测试项目上传到此处



在Vcl.Graphics.pas中编辑SetSize()以在负数上退出后,异常似乎消失了。
这不能解决导致异常的原因,因为为什么在DrawListBoxVertScroll中将参数设置为-1仍是未知的(错误?也可能是此例程中更多子调用的结果),但是至少是
a修复程序可以防止异常。在我们发生异常的所有机器上进行了测试,均获得了积极的结果。



我们很想听听一些真正的VCL专家(例如Remy Lebeau甚至是VCL开发人员)的意见



我再次意识到,不是每个人都可以重现异常,但是通过上面链接的测试项目,异常在我们的系统中是不可避免的。


I am experiencing a crash / exception when using a simple TOpenDialog with VCL Styles enabled.

Without the styles enabled, the dialog is of course working fine. The issue occurs with C++ Builder 10 and 10.1 Professional.

To reproduce:

  1. create a simpe VCL Form that uses styles
  2. add a TComboBox, a TButton and a TOpenDialog to the form
  3. add the following code to the OnClick event for the button

    OpenDialog1->Execute();
    for(int i=0; i<100; i++)
      ComboBox1->Items->Add("test text");
    ComboBox1->ItemIndex = 1;
    

  4. run the application, click the button and select a file

  5. For me, this yields to an exception 'Out of system resources'

This bug could be reproduced on Windows 7 Enterprise and Windows 8.1 Pro. Having the same issue with a TSaveDialog.

The weird thing for me is that regarding this exception, I can't find similar issues on the web. In my opinion, with only VCL styles and TOpenDialog required to have this, I would expect more information about this on the web.

I only found something remotely similar, but not an exception there and also no solution in terms of native VCL styles:

Using custom styles shows invalid characters when right-clicking a file in TOpenDialog

I tried also to disable SystemHooks shDialogs (please see screenshot) which I read somewhere regarding another problem with VCL styles, but to no avail.


* Edit 2016/05/26 *

Remy Lebeau is asking for a MCVE. I tried to put everything in the question, but for clarity here an abstract for a MCVE:

  • create new VCL project with default settings
  • drop a TComboBox, a TButton and a TOpenDialog into the form
  • add the following code to the OnClick event for the button:

    void __fastcall TForm1::Button1Click(TObject *Sender) 
    {
      OpenDialog1->Execute();
      for (int i=0; i<100; i++)
        ComboBox1->Items->Add(L"test text");
      ComboBox1->ItemIndex = 1;   // <- exception occurs here
    }
    

  • enable a VCL style 'Smokey Quartz Kamri' in the project options

  • run program, press button, select any file and select OK in TOpenDialog

Here, this is really all it takes for the exception.

In my opinion, the call to Execute() messes up some VCL structures (only if styles are enabled) and then the access to another VCL item (combobox in my case) leads to the crash.

I am now aware that not every one has this crash. So forgive me if it is not a 100% verifiable example for each of you.

But me and my colleague can't be the only ones who have this crash (tested now on 4 different computers with 3 different OS versions), can we?

* Edit 2016/05/27 *

Regarding Tom Brunberg's request for single step, the exception occurs somewhere within WndProc, in the screenshot at address 005459F4 within the call.

If I step further, I am landing somewhere in TCustomCombo.WndProc. After that is is very hard to follow further because of repeating loops in WndProc, can't seem to reach the final place where the exception fires.

* Edit 2016/05/27 second *

OK I managed to pinpoint the exact location of the crash. Is in in the function CopyBitmap within VCL.Graphics. In the first screenshot, exception occurs at line:

Result := GDICheck(CreateCompatibleBitmap(ScreenDC, bmWidth, bmHeight))

In the function GDICheck() in the second screenshot, the variable Value is zero in the debugger, so in turn function GDIError is called. There, ErrorCode is zero as well, this leads to the call to OutOfResources.

Hope this helps to narrow it down further.


* Edit 2016/07/19 *

Since nobody here seemed to have the issue, we gave it a different try: A colleague of mine in the company did a fresh C++ Builder 10.1 Berlin install, in English (thought maybe the German IDE is the culprit), and first thing after the install, recreated the StylesCrashTest App. Result is the same, it crashes at once after selecting a file and hit 'open' in the dialog.

I have uploaded the test project here http://fboom.me/file/9904e22ddd22b/StylesCrashTest.zip

and our generated release exe here http://fboom.me/file/368d0b62cc1a7/StylesCrashTest.exe

The exe is tested with many antivirus scanners on virustotal.com. https://www.virustotal.com/de/file/e96f2e7eb80c162c2e5998decc15f26615c9fc76efec73379dd2e2140e4eba08/analysis/1468952442/

It would be helpful if you guys could test the exe and the test project and this could lead to separate the issue to either computer related or related to the installed IDE/generated exe. This of course only if someone can reproduce the issue.

With this exe, the app crashes here on two Windows 7 x64 Enterprise computers in a commercial environment. It does not, however, crash on my private computer with Windows 8.1 x64 Prof.

Right now I am at a dead end, nobody outside the town of Munich seems to be able to reproduce the issue, but we have it definitely on two different computers.

The issue is also filed with Embarcadero (login required): https://quality.embarcadero.com/browse/RSP-15019

Sadly, at the moment, this is a shop stopper for us for using VCL styles.

解决方案

I found a fix to get rid of the crash. After some more debugging, it was discovered that the exception occurs every time TBitmap::SetSize is called with a negative parameter on the VCL styled TComboBox.

Please see the call stack in the attached screenshot:

TComboBoxStyleHook::ListBoxWndProc
TComboBoxStyleHook::DrawListBoxVertScroll
TBitmap::SetHeight
TBitmap::SetSize

After editing SetSize() in Vcl.Graphics.pas to exit on negative numbers the exceptions seems to be gone. This is no fix for the cause of the exception, because why the parameter is set to -1 in DrawListBoxVertScroll is still unknown (bug?, could also be the result of a lot more sub calls within this routine), but at least it is a fix to prevent the exception. Tested on all our machines where the exception took place with positive results.

Would love to hear the opinion of some real VCL experts like Remy Lebeau or even the VCL developers about it, though.

Again, I realize that not everybody can even reproduce the exception, but with the test project linked above, the exception is inevitable on our systems.

这篇关于使用VCL样式在TOpenDialog中给出异常/崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆