Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 477 478 [479] 480 481 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 909327 times)

Tylui

  • Bay Watcher
  • O_o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7170 on: April 13, 2015, 07:44:34 pm »

Well, have you actually implemented MapSystem::NatureRegion::NatureRegion()? Is that method visible from where you're calling it? Can you pastebin all the relevant files, please?
http://pastebin.com/Envmn6MG

For GameMap.cpp I just included the offending function. The line in particular that is causing the problem, that I was discussing above, is line 49. The class NatureRegion is in the file GameMap.h. The definition of the vector NatureRegionsContainers is at the bottom of the class GameMap, in the file GameMap.h. Thank you ahead of time for any assistance given. The errors are at the very bottom of the pastebin link.

Can you also pastebin the parts of the code where NatureRegion class and NatureRegion method are?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7171 on: April 13, 2015, 10:01:15 pm »

I think I sorted the issue then ...

You don't have fuction bodies on your class methods. It's nothing to do with the calling code in that case.

Quote
    NatureRegion();
    ~NatureRegion();

These are only declarations. A function without a body is supposed to be defined elsewhere. At least just stick an empty body with each one to kill the errors:

Quote
    NatureRegion() {};
    ~NatureRegion() {};

Every method needs a function body, either defined inside the class or linked from outside.
« Last Edit: April 14, 2015, 01:26:44 am by Reelya »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7172 on: April 13, 2015, 10:15:20 pm »

So, I'm working on some graphics tutorials with some folks, generally using C++ with OpenGL or OpenGL-like stuff. Intention being minimal explanation outside the code itself, using simple, understandable coding style to do so.

Question: what is the most confusing part of this code? Or in general, what would most keep you from arbitrarily modifying it into something with similar code but different results? https://github.com/jalway/tut0

I'm going to admit that I'm impressed that it's possible to create an OpenGL window that can render anything with so few lines.  That said, I learned OpenGL back when the only way to get things to render was to use glVertex3f and its cousins to send vertices to the GPU.  I think that's called immediate mode these days?

Anyway, the only thing that I was curious about while looking through it is where the libraries came from that are letting you create a Win32 window with such little code.  I guess it's not the point of the tutorial to show Win32 window creation, message pumps and all of that nastiness, so it makes sense to use a library to manage that for you.
Yeah, this set of tutorials I'm working on is specifically not introducing vertex/index buffers until later (and probably that sort of immediate mode never, since I don't think it's actually relevant any more due to performance reasons). Bunch of reasons, but it boils down to those things being very complex ideas to thrust on a beginner with no understanding of the GPU in combination with the fact that the sort of high-end graphics programming for game engines is actually moving away from it and towards variations on vertex pulling and such. As such, there is a much stronger focus on data and information, rather than magic vertex buffers depending so strongly on the API as to obfuscate what is actually going on. Those will instead be explained in terms of having the earlier tutorials involving actually implementing their functionality with plain old buffers and introducing them for what they are using previous concepts... That's the idea anyway.

As for window creation and that sort of thing, I think the others have written some code detailing those, so that falls outside of what I'm attempting to accomplish here.
Logged

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7173 on: April 14, 2015, 10:51:47 am »

I learned two new things about Pascal today:

First, dynamic multidimentional arrays are possible:
Code: [Select]
Foo:array of array of string;
Bar:array of array of array of string;
Baz:array of array of array of array of string;
//etc.

Second, Pascal has an exponentiation operator.
Code: [Select]
Foo:=7**7;
Bar:=2**-1;
Baz:=Foo**Bar;
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Tylui

  • Bay Watcher
  • O_o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7174 on: April 14, 2015, 12:35:00 pm »

-snip- dynamic multidimentional arrays -snip-

A few days ago I learned that those are called jagged arrays! Thought that was a fun name
Logged

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7175 on: April 14, 2015, 02:24:17 pm »

I think I sorted the issue then ...

You don't have fuction bodies on your class methods. It's nothing to do with the calling code in that case.

Quote
    NatureRegion();
    ~NatureRegion();

These are only declarations. A function without a body is supposed to be defined elsewhere. At least just stick an empty body with each one to kill the errors:

Quote
    NatureRegion() {};
    ~NatureRegion() {};

Every method needs a function body, either defined inside the class or linked from outside.

That fixed it. I wasn't aware that a body was needed, even if it is empty. I must have just added a body in some other cases, without thinking about it. It's always the little things that you have look out for. Thank you, and all others who helped.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7176 on: April 14, 2015, 02:26:39 pm »

Second, Pascal has an exponentiation operator.
Code: [Select]
Foo:=7**7;
Bar:=2**-1;
Baz:=Foo**Bar;

haha yeah it's kind of fun how so many languages seem to use completely different exponentiation

Lua:

Code: [Select]
foo=5^3
Python:

Code: [Select]
foo=5**3
Javascript:

Code: [Select]
foo=Math.pow(5,3)
javascript makes me sad

Tylui

  • Bay Watcher
  • O_o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7177 on: April 14, 2015, 03:00:58 pm »

Javascript:

Code: [Select]
foo=Math.pow(5,3)
javascript makes me sad

And I guess all the c-languages too...
Logged

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7178 on: April 14, 2015, 03:04:23 pm »

Yeah, Pascal also has a power function. I just didn't know about the operator.
These are almost identical, as in they return the same values.
Code: [Select]
Foo:=power(2,5);
Bar:=2**5;
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7179 on: April 14, 2015, 07:26:01 pm »

It didn't take long to hit another issue. Areas such as this problem are things that I generally don't understand well. This time the code builds just fine, it just crashes when it is run. I tracked down the exact line that causes the crash. I have already searched for solutions on google, and could not find what I was looking for.

The relevant code: http://pastebin.com/A3TyS9W6

Line 186 is what is causing the crash:
Code: [Select]
if(ContainedCoordinates[Position].x == ax && ContainedCoordinates[Position].y == ay)What I was trying to do is access the x member of the object stored in the vector (ContainedCoordinates). Objects of the class 'CartesianCoordinate' are stored in the vector, and the declaration of the class is in the paste.

The CartesianCoordinate class contains just two member variables.
Code: [Select]
int x;
int y;
I am not entirely sure what I did wrong. Please let me know if you require addition information, thank you.
 
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7180 on: April 14, 2015, 07:43:59 pm »

It's clear what your code is trying to do, and you have the basic right ideas. There are just a couple of errors/typos and some logic operators you have the wrong way around. Plus, I'll show you a more optimized way to do it in a lot less code.

This is another case where that isn't the line that's causing the crash. The line where it is crashing is not normally the line with the error in it. It's because your array index is going past the end of the array, then the next time it hits that line it crashes.


Here's a suggested replacement function:

    bool MapSystem::NatureRegion::Contains(int ax, int ay)
    {
        for(int Position = 0; Position < ContainedCoordinates.size(); Position++)
            if(ContainedCoordinates[Position].x == ax && ContainedCoordinates[Position].y == ay)
                return 1;
        return 0;
    }

so, this will basically loop over every valid index, and if it's found will return 1 straight away. If it gets to the end, it will return 0. If you want a loop iterator version, you need to get rid of the Position value altogether, and use the iterator inside the loop to access the data rather than using the [] operator.

It would be something along the lines of ...

    bool MapSystem::NatureRegion::Contains(int ax, int ay)
    {
        for( std::vector <CartesianCoordinate>::iterator CurrentVectorPos = ContainedCoordinates.begin();
                   CurrentVectorPos != ContainedCoordinates.end(); CurrentVectorPos ++)
            if( (*CurrentVectorPos).x == ax && (*CurrentVectorPos).y == ay)
                return 1;
        return 0;
    }

you can do it with for loops or while loops, the logic is the same. I prefer the int index one myself for a vector, it's simpler and faster.
« Last Edit: April 15, 2015, 03:39:12 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7181 on: April 15, 2015, 03:38:27 am »

!ErrorHasOccured() ??!??! HandleError();

This is an incredibly expressive line of code. (C)
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Ghills

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7182 on: April 15, 2015, 12:53:31 pm »


This is another case where that isn't the line that's causing the crash. The line where it is crashing is not normally the line with the error in it.

QFT.  IME this is the #1 cause of hair loss among programmers.  Learning to trace logic to see what previous mistakes could cause a crash is vital.

Error reporting can't tell a programmer what caused the problem. It can only say where the problem happened.  Kind of like a 911 call that can only report the house address but not what's happening.
Logged
I AM POINTY DEATH INCARNATE
Ye know, being an usurper overseer gone mad with power isn't too bad. It's honestly not that different from being a normal overseer.
To summarize:
They do an epic face. If that fails, they beat said object to death with their beard.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7183 on: April 15, 2015, 05:26:17 pm »

The issue is that code can't tell what you were trying to write. Say you're meant to loop to <= a value, but you only put <, so it's missing one iteration. This could cause all sorts of glitches, but it's not like there's a human-level AI in there which knows what you meant. This is one thing that frustrates programmers: "why didn't the computer notice my error? why isn't it more specific". But being specific usually entails some analysis of what you intended to write, which is not objectively clear. It requires intelligence with a knowledge of the problem domain you're trying to solve and algorithms, analysing which algorithm you intended to implement, and what you did wrong. Which is far outside the scope of a compiler.

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7184 on: April 15, 2015, 08:51:51 pm »

Once again, thank you Reelya. I hadn't expected it to be an issue of going out of array bounds, and missed the fact that I advanced 'Position' but not the vector iterator.

To the mention of finding issues and solving them on your own. The thing I have found extremely useful, and that I recommend to other beginner programmers is to just output some debug info of complex functions into a text file. That has been extremely helpful for me, and has aided in fixing many issues in my code. I know there are more complex and useful options available. But, that alone can be extremely helpful.
Logged
Pages: 1 ... 477 478 [479] 480 481 ... 796