Beginning C++ Tutorial 14

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
DrewAmu
Posts: 4
Joined: June 25th, 2019, 12:13 am

Beginning C++ Tutorial 14

Post by DrewAmu » June 25th, 2019, 1:00 am

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.

WilsonHuang
Posts: 8
Joined: February 13th, 2019, 3:23 am

Re: Beginning C++ Tutorial 14

Post by WilsonHuang » June 25th, 2019, 2:55 am

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
未命名.png
(67.98 KiB) Not downloaded yet

DrewAmu
Posts: 4
Joined: June 25th, 2019, 12:13 am

Re: Beginning C++ Tutorial 14

Post by DrewAmu » June 27th, 2019, 9:20 pm

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.

albinopapa
Posts: 3822
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginning C++ Tutorial 14

Post by albinopapa » June 28th, 2019, 3:09 am

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

DrewAmu
Posts: 4
Joined: June 25th, 2019, 12:13 am

Re: Beginning C++ Tutorial 14

Post by DrewAmu » July 4th, 2019, 1:33 am

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.
Attachments
Snek_Engine.zip
Source files from Snek game
(3.99 MiB) Downloaded 15 times

albinopapa
Posts: 3822
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginning C++ Tutorial 14

Post by albinopapa » July 5th, 2019, 3:18 am

Code: Select all

Game::Game( MainWindow& wnd )
	:
	wnd( wnd ),
	gfx( wnd ),
	brd(brd), 
	rng(std::random_device()())
{
}
There is an error here.
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

DrewAmu
Posts: 4
Joined: June 25th, 2019, 12:13 am

Re: Beginning C++ Tutorial 14

Post by DrewAmu » July 5th, 2019, 5:48 pm

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.

albinopapa
Posts: 3822
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginning C++ Tutorial 14

Post by albinopapa » July 6th, 2019, 3:53 am

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

ariston
Posts: 1
Joined: July 9th, 2019, 8:40 pm

Re: Beginning C++ Tutorial 14

Post by ariston » July 9th, 2019, 8:42 pm

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

albinopapa
Posts: 3822
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Beginning C++ Tutorial 14

Post by albinopapa » July 9th, 2019, 10:08 pm

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

Post Reply