0

I'm having an issue with rendering text using DWrite.h in DirectX 11. I'm trying to wrote an application that will work as menu for my future game. When I'm displaying buttons, sometimes (not always) I'm getting error (visual studio shows it on ID2D1RenderTarget::EndDraw() in Button.cpp). Error ain't saying much ("Gra.exe has triggered a breakpoint") in lane which I've mentioned. When I click "Continue button" it displays that problem is about "corruption of heap". I've tried to find problem for my own for few days. I've checked all memory allocation etc., but I've found nothing. Weird thing is that this error is totally random - sometimes it shows, sometimes doesn't.

There are links to my codes:

http://pastebin.com/wS91uU2P

I would be greatful for any help.

Kamil Przybyo
  • 115
  • 1
  • 8
  • Take your time and format your question, include relevant codes here. In my opinion no one would debug your code, especially like this... :/ – NMD Mar 11 '16 at 15:11
  • It's hard to form it in other way. VS doesn't really say what's going on and where. – Kamil Przybyo Mar 11 '16 at 15:49
  • Errors just seem to be random, try to encapsulate the problem. Maybe some missing intialisation of static classes and so on. I think no one will read your whole repo for finding the error. – kaiser Mar 12 '16 at 16:10
  • txtProperties_.text = new wchar_t[wcslen(newTxt)]; When I've changed size of this array to be "wcslen(newTxt)+1" application is not crashing now so hard. Before that change it was running properly once in 30 tries, not it's crashing very rarely. Can someone tell me why I should alloc it like this? I was using safe functions to copy values and it was impossible that they were copying too much. Just don't get it. – Kamil Przybyo Mar 13 '16 at 21:34
  • Why do you use the new operator here? easiest is to just use std::string or std::wstring. This does allocation for you. If you need a pointer to a w_char, just call std::wstring.c_str() to get that pointer. – kaiser Mar 15 '16 at 04:06
  • PS: If you are calling addTextToDisp twice, then you have a memory leak. Seems your memory management is totally unsafe... txtProperties_.text should definitly be a std::wstring!!! – kaiser Mar 15 '16 at 04:15

0 Answers0