c++ - DX11 Mapping vertex buffer as WRL::ComPtr -


i'm having trouble mapping vertex buffer. when so:

id3d11buffer* pd3dsinglevertexbuffer; ... pd3dimmediatecontext->map(pd3dsinglevertexbuffer, null, d3d11_map_write_discard, null, &mappedsubresource); 

everything works, frames works properly. however, when things that:

microsoft::wrl::comptr<id3d11buffer> pd3dsinglevertexbuffer; ... pd3dimmediatecontext->map(pd3dsinglevertexbuffer.get(), null, d3d11_map_write_discard, null, &mappedsubresource); 

nothing gets rendered, application doesn't crash, nor there errors.

do know doing wrong?

as discovered, while classic approach creating single-element arrays used in d3d use address-of operator on single element, it's commonly used pass output paramaters creation methods (e.g. createdevice(&device)). since more common usage, in context of entire win32 api surface, comptr designed safely provide output-parameter semantics, release()ing contained object prior returning address.

there 2 ways around problem. first create array of objects, e.g. id3d11buffer** ppbuffers[] = { pbuffer.get() };. second utilize comptr::getaddressof returns address of contained object without changing refcount. in latter case, careful not use in cases using container output parameter, otherwise you'll leak held object.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -