Beginning C++ Tutorial 14
Beginning C++ Tutorial 14
Stuck in Chili Tutorial 14a -please advise me what may be causing this problem: I got to the point in the tutorial where I'm "testing the grid" right before coding the Snake class; I downloaded the Tutorial 14 Framework and added the code exactly as shown in the Tutorial; The program crashes - actually it terminates itself after flashing a white screen. I don't get an "Assertion Failed" error. In Debug mode I get an "Un-handled Exception" at the line which starts with pSysBuffer in the PutPixel function in the Graphics.cpp file. I'm using Visual Studio 2017, Windows 10 - 64 bit and have not had this problem doing all the previous Tutorials. I would appreciate suggestions.
-
- Posts: 44
- Joined: February 13th, 2019, 3:23 am
Re: Beginning C++ Tutorial 14
Hi, DrewAmu, please check the Solution Configuration is switched to "Debug".
If the solution configuration is release mode. The assertion check will be skipped
UPDATED:
Be sure your value of x in PutPixel is between 0 and 799, y is between 0 to 599
If the solution configuration is release mode. The assertion check will be skipped
UPDATED:
Be sure your value of x in PutPixel is between 0 and 799, y is between 0 to 599
Re: Beginning C++ Tutorial 14
The issue seems to be that in the ComposeFrame function the Color object "c" is initialized with the r, g, and b values which are between 0 - 255, then when it jumps to the DrawCell function "c" contains (apparently) meaningless integer values with many digits. I am assuming that these values are causing the Exception to be thrown when they are passed to the PutPixel function. I don't really understand how the Color class overloaded constructors work but I think that may be where the values are getting corrupted.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginning C++ Tutorial 14
Not likely unless you changed something. If you can't figure it out after doing some debugging, either upload a compressed copy of your solution and subfolders or share the github address to your repository and we'll try to steer you in the right direction.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Beginning C++ Tutorial 14
After carefully following the values while stepping slowly through the program, I realized that what I guessed in the above reply was wrong. The values were all as expected right up until I got this message: Exception thrown read access violation; This was nullptr.
Here is what solved the problem: Instead of the "cache" method that Chili used to store the Graphics reference in Board class, I passed the Graphics reference in the DrawCell function along with the Location and Color references, and removed the Graphics constructor from Board. I don't understand why this worked, since the two ways of referencing Graphics should be equivalent. I also don't understand why the cache method didn't work for me since I haven't heard of anyone else having this problem. I'm uploading the source files (entire Engine folder) in case anyone would like to try to figure this out.
Here is what solved the problem: Instead of the "cache" method that Chili used to store the Graphics reference in Board class, I passed the Graphics reference in the DrawCell function along with the Location and Color references, and removed the Graphics constructor from Board. I don't understand why this worked, since the two ways of referencing Graphics should be equivalent. I also don't understand why the cache method didn't work for me since I haven't heard of anyone else having this problem. I'm uploading the source files (entire Engine folder) in case anyone would like to try to figure this out.
- Attachments
-
- Snek_Engine.zip
- Source files from Snek game
- (3.99 MiB) Downloaded 149 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginning C++ Tutorial 14
Code: Select all
Game::Game( MainWindow& wnd )
:
wnd( wnd ),
gfx( wnd ),
brd(brd),
rng(std::random_device()())
{
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Beginning C++ Tutorial 14
Thank you! I knew there had to be some dumbass error somewhere, but I just couldn't see it. Even though I was able to get the program to run it bothered me that it wouldn't work the way it was supposed to. I feel better now.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginning C++ Tutorial 14
Awesome.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Beginning C++ Tutorial 14
Hey guys, for some reason when I'm trying to run the code with the board class, just before adding the snake class, my grid only shows blue color.
My random generator works because the blue shade changes value, however the red and green do nothing.
I tried changing them manually but still nothing
My random generator works because the blue shade changes value, however the red and green do nothing.
I tried changing them manually but still nothing
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Beginning C++ Tutorial 14
What have you changed, the version you posted after fixing showed random colors and not just blue.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com