Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft BreakPoint called, pbly Heap corruption while running "example-06-bump" #10

Closed
jeremieroy opened this issue Feb 12, 2013 · 16 comments

Comments

@jeremieroy
Copy link
Contributor

This occurs systematically with a DX9 renderer.
Switchint to MonoThreaded help tracking down the issue:
It leads to Line 649 of renderer_d3d9.cpp.

for (uint32_t stage = 0; stage < BGFX_STATE_TEX_COUNT; ++stage)
{
(there) --> DX_CHECK(m_device->SetTexture(stage, NULL) );
}

I try to fix it, but I didn't get to find the root cause.
Googling doesn't help.
However the case below seems to share root cause similarities:
http://stackoverflow.com/questions/14034101/unbind-texture-bound-using-id3dxeffect-settexture

Any idea ?

Btw, thx a lot for sharing bgfx. It is a beautiful code base.
Never seen a renderer so bold and uncluttered.
Didn't dig everywhere yet, but it looks like a pure submission engine, which is pretty exciting to say the least :)

@bkaradzic
Copy link
Owner

I'll take a look, can you post some info about your GPU and drivers?

@jeremieroy
Copy link
Contributor Author

Here are some info:
OS: Win7 64bits.
CC: Msvc 2010

Driver

Driver Packaging Version 8.97.100.3-120703a-145534C-ATI
Catalyst Version 12.6
Provider Advanced Micro Devices, Inc.
2D Driver Version 8.01.01.1248
Direct3D Version 7.14.10.0911
OpenGL Version 6.14.10.11653
Catalyst Control Center Version 2012.0704.122.388

Hardware: ATI Radeon HD 4850

Graphics Card Manufacturer Built by AMD
Graphics Chipset ATI Radeon HD 4800 Series
Device ID 9442
Vendor 1002
Subsystem ID 0502
Subsystem Vendor ID 1002
Graphics Bus Capability PCI Express 2.0
Maximum Bus Setting PCI Express 2.0 x16
BIOS Version 011.003.000.000
BIOS Part Number 113-B50102-103
BIOS Date 2008/05/23
Memory Size 512 MB
Memory Type GDDR3
Core Clock in MHz 625 MHz
Memory Clock in MHz 993 MHz
Total Memory Bandwidth in GByte/s 63,6 GByte/s

@bkaradzic
Copy link
Owner

Are you getting assert even with example 01-cubes?

@jeremieroy
Copy link
Contributor Author

No, only with the bump sample.
And the crash occurs during bgfx shutdown, rendering works fine.
Btw, is there any way to declare lines and triangles strips ?

@jeremieroy
Copy link
Contributor Author

I didn't find a way to control the scissor test explicitly. Is there any ? (only looked at the openGL renderer on this point)
I can use bgfx::setViewRect(...)
But this rely on changing the viewport, not the scissor test. The scissor test seems enabled only when clearing the buffer.

This look like a potential bug...
Details there: 10. The Viewport Does Not Clip or Scissor
on this page
http://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/

@bkaradzic
Copy link
Owner

That's from some ancient days. Nowadays viewport does clipping too. Scissor test is needed only when you want to clip inside viewport. Anyhow, reason why I don't have scissor test API exposed is because I didn't need it yet. Everything in bgfx gets added when it's needed and when I have coverage test for the feature. That way library can stay lean and avoid bugs from code that exist but never gets touched in my tests.

Anyhow, I see you'll need scissor test here:
https://github.com/jeremieroy/bgfxGWEN/blob/master/Renderer/bgfxRenderer.cpp

If you commit other changes I can grab it and test it, and see what are requirements for scissor test for your lib and add it so that you could use it. For now you could use just views to provide scissoring for UI objects. Also it's great that you picked GUI lib because it can be used to demonstrate sequential drawing. That's said keep in mind that bgfx by default doesn't draw in the order of submission, but rather sorts all primitives by certain criteria and submits in that sorted order.

Also if the original bug you reported appears only in your code and you can't reproduce it in any of bgfx examples, it would be better if you could create small reproducible case so that I can test it and fix it.

@jeremieroy
Copy link
Contributor Author

Ok, I'll try to implement the renderer using viewport and see how it goes.
I assume the viewRect is saved as part of the render state during a submit ?

"Also if the original bug you reported appears only in your code and you
can't reproduce it in any of bgfx examples,"

The original bug appears 100% of the time with the sample "06-bump", when
the sample close.
It calls bgfx::shutdown, then try to do a setTexture(.., NULL) on the
DirectX9 device and then crash.

My own code is not doing anything yet...

2013/2/13 Branimir Karadžić notifications@github.com

That's from some ancient days. Nowadays viewport does clipping too.
Scissor test is needed only when you want to clip inside viewport. Anyhow,
reason why I don't have scissor test API exposed is because I didn't need
it yet. Everything in bgfx gets added when it's needed and when I have
coverage test for the feature. That way library can stay lean and avoid
bugs from code that exist but never gets touched in my tests.

Anyhow, I see you'll need scissor test here:

https://github.com/jeremieroy/bgfxGWEN/blob/master/Renderer/bgfxRenderer.cpp

If you commit other changes I can grab it and test it, and see what are
requirements for scissor test for your lib and add it so that you could use
it. Also it's great that you picked GUI lib because it can be used to
demonstrate sequential drawing. That's said keep in mind that bgfx by
default doesn't draw in the order of submission, but rather sorts all
primitives by certain criteria and submits in that sorted order.

Also if the original bug you reported appears only in your code and you
can't reproduce it in any of bgfx examples, it would be better if you could
create small reproduce so that I can test it and fix it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-13472750.

@bkaradzic
Copy link
Owner

setViewRect is global, there are 32 of them. Anyhow, as a first pass try just rendering everything in main view, and then we'll see about scissor.

I can't repro crash on mine here with 06-bump example, but I'm going to debug it more tomorrow.

@bkaradzic
Copy link
Owner

I'm unable to reproduce this issue, you'll need to debug on your machine and give me more info about the error (in DX control panel enable debug runtime) or create repro case.

@jeremieroy
Copy link
Contributor Author

I enabled DirectX debug, not sure if it helps.
(I skipped the redundant setRenderState)

Direct3D9: :Dynamic index buffer locked twice or more in a row without D3DLOCK_NOOVERWRITE or D3DLOCK_DISCARD. Could have severe performance penalty.
Direct3D9: :Dynamic vertex buffer locked twice or more in a row without D3DLOCK_NOOVERWRITE or D3DLOCK_DISCARD. Could have severe performance penalty.
...(lot of double locking later) ... and some redundant setRenderState
..\..\..\src\bgfx.cpp(727): BGFX shutdown
HEAP[example-06-bumpDebug.exe]: Heap block at 082A0040 modified at 082F55E0 past requested size of 55598
Windows has triggered a breakpoint in example-06-bumpDebug.exe.

This may be due to a corruption of the heap, which indicates a bug in example-06-bumpDebug.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while example-06-bumpDebug.exe has focus.

The output window may have more diagnostic information.

Maybe it's in my ATI driver ?

@bkaradzic
Copy link
Owner

I don't think it's ATI drivers... It seems there is memory corruption somewhere. I'm not seeing this, but I'm going to run it with ApplicationVerifier to check, maybe it will point out what's wrong.

@bkaradzic
Copy link
Owner

Found it, DX9 lock texture for BC5 texture lowest mip level returns 8 bytes instead 16... Since it's 4x4 block it should be 16 bytes, but for some reason memory available is only 8 bytes. I need to research more about why this happens.

@bkaradzic
Copy link
Owner

It should be fixed: 8a499e6

@jeremieroy
Copy link
Contributor Author

The crash is gone !
However,I still have a suspicious warning message :
......\src\bgfx.cpp(764): BGFX WARN LEAK: m_vertexDeclHandle 2 (max: 64)

@jeremieroy
Copy link
Contributor Author

Also (it is not new) But geometryc doesn't compile in release under vs2010 due to warning as error:

Error   1   error C4701: potentially uninitialized local variable 'triangle' used
h:\github\bgfx\tools\geometryc\geometryc.cpp    499

A simple fix is to add

memset(&triangle,0,sizeof(Triangle));

at line 500 to close the compiler mouth, since the logic seems fine and the warning not legit.
Visual studio doesn't seems to understand when switch are used as small state machine.

@bkaradzic
Copy link
Owner

bgfx.cpp(764): BGFX WARN LEAK: m_vertexDeclHandle 2 (max: 64)

It's known issue, it's just there for me as reminder that I have to fix it.

error C4701: potentially uninitialized local variable 'triangle' used

I'll fix this one later.

Qix- pushed a commit to tidemmo/bgfx that referenced this issue Jan 9, 2020
not removing the egl/ppapi gles2 contexts
CedricGuillemet pushed a commit to CedricGuillemet/bgfx that referenced this issue Dec 14, 2020
Respect BGFX_RESET_FLIP_AFTER_RENDER during Init
andrewwillmott pushed a commit to andrewwillmott/bgfx that referenced this issue Feb 8, 2024
* Option to pick a device by indexing into the enumeration returned by the API (VK only)

* save out final device index

* select the first suitable GPU instead of the last, and if the user requests a specific GPU don't override it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants