关于线程中CreateDIBSection的调用
在名为 buildtexture 的函数中,它加载图像并为 OpenGL 构建纹理,当我调用 CreateDIBSection 时,它将创建一个位图。如果将函数 buildtexture 作为普通成员函数调用,则不会有任何问题。但是如果我在线程中调用这个成员函数,CreateDIBSection 将返回 0,这意味着它失败了。甚至在调用CreateDIBSection后,GetLastError也返回0。我猜线程没有足够的空间来创建位图。而且我不知道如何解决这个问题。任何人都可以帮助我吗?非常感谢!
in a function named buildtexture, it loaded the image and build texture for OpenGL, when i called CreateDIBSection, it will creat a bitmap. If the function buildtexture was called as a normal member function, there will be nothing wrong. But if i called this member function in a thread, the CreateDIBSection will return 0 that means it failed. And even the GetLastError alse returned 0 after the calling of CreateDIBSection. I guess the thread has no enough spaces to create the bitmap. And i don't know how to solve this problem. Any one can help me? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太可能是内存不足错误。
CreateDibSection需要HDC,你从哪里得到它?是不是另一个线程拿到了然后交给你了?
在除获取 DC 的线程之外的线程中使用 DC 是合法的。但是,当您在多个线程中使用 DC 时,您需要确保 DC 的使用是串行的。
确保当您尝试使用 DC 时它仍然有效,并且一次只有一个线程正在尝试使用它。
Not likely to be an out of memory error.
CreateDibSection needs a HDC, where did you get it? Did another thread get it and then hand it to you?
It is legal to use a DC in a thread other than the one that got it. but you need to insure that use of the DC is serialized when you use it in more than one thread.
Make sure that the DC is still valid when you try and use it, and that only one thread at a time is trying to use it.
你的错误意味着你没有删除 Hdc
在CreateDIBSection 之前必须删除新的Hdc。
但如何! HDC有什么新来的
在更改之前先获取旧的 Hdc。
首先CreateDIBSection之后,每次Resize表单、关闭表单时Hdc都会改变
和最小化形式
如果 CreateDIBSectio 返回 0
你很可能会删除Hdc
That fault you have is mean you not delete Hdc
Before CreateDIBSection must be delete new Hdc.
But how! what is new HDC come
Just get the old Hdc first befor change.
After CreateDIBSection at first Hdc will change when very time Resize form , Close form
and Minimize form
If that CreateDIBSectio return 0
You much be delete Hdc