0

I'm writing a Windows Form card game and am having trouble assigning an image to my cards. When I debug my code below, the method seems to return unexpectedly as soon as it reaches the GetObject method. Am I using this method improperly? If so, can anyone provide a better solution?

private void initCards()
    {
        ResourceManager rm = new ResourceManager(typeof(Image));       
        for (int i = 0; i < 4; i++)
        {
            for (int j = 102; j < 115; j++)
            {
                int tempId = j + (i * 100);
                Card tempCard = new Card(tempId);
                object obj = rm.GetObject("card"+tempId);
                int x = 12;
                tempCard.setImage((Image)obj);
                deck.Add(tempCard);
            }
        }
    }
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
  • 1
    It sounds like you're swallowing an exception. Look for `catch` blocks. – SLaks Apr 07 '14 at 02:41
  • That doesn't sound right. The `GetObject` method cannot make the method end just like that unless it's throwing an exception. – Crono Apr 07 '14 at 02:41
  • You are probably swallowing an exception somewhere as a method can't just "return" half way through. Find this place (look for try-catch blocks) and see what the exception text is. – Andrew Savinykh Apr 07 '14 at 02:42
  • @SLaks My thoughts exactly - but if `initCards` is being called by a WinForms Event handler (e.g. `Form_Load`) then the exception will be swallowed too, without a `catch` statement in user-code. – Dai Apr 07 '14 at 02:42
  • On an unrelated note, the amount of magic numbers (https://en.wikipedia.org/wiki/Magic_number_(programming)) shown in this snippet is truly astounding. – Jesse C. Slicer Apr 07 '14 at 04:00
  • You could try to change the debug setting of visual studio to break when an exception is thrown http://msdn.microsoft.com/en-us/library/d14azbfh.aspx – rene Apr 07 '14 at 10:15

0 Answers0