Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Problems with agk::LoadImage in tier 2

Author
Message
United Calamity
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Canada
Posted: 1st Aug 2015 05:20
The title pretty much says it all. I am trying to load an image in C++ using agk::LoadImage, but I get this error.


My code is simple:


Yes it's in a header file.

I hate to be so blunt, but it makes no sense. When I get the error in VS 2013 it just gives the error and points to that line of code. If I change it LoadSprite and get rid of that all together, I get the same error.

Everything is in different file, but the player does include this.

Thanks in advance

Gamejolt: http://gamejolt.com/profile/united-calamity/575975
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Aug 2015 18:08
hmm does this work?
int playerImage = agk::LoadImage("SprPlayer.png");

AGK 108 (B)19 + AppGameKit (Steam) V2 Beta .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
United Calamity
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Canada
Posted: 1st Aug 2015 20:04
Unfortunately, no. But thanks for the suggestion. "Integer" is typedef in Constants.h to int. So it really makes no difference.

Gamejolt: http://gamejolt.com/profile/united-calamity/575975
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 1st Aug 2015 21:30
Quote: "Yes it's in a header file."

OK so from what you've said, I think the problem is where you're calling the function. If you put this code instead of a header, then it will simply be pasted into the file that you include it to. Looking at this

will be interpreted as a global variable with an initialiser. Therefore when your program loads, it will call agk::LoadImage. This will crash, because AppGameKit won't have loaded yet, and so will itself be in an uninitialised state. You need all of your code to appear within the three functions of the app class (app::Begin(), app::Loop(), app::End()). If you call AppGameKit functions before you are given control in the app::Begin function, it will likely crash.

I hope that helps.

United Calamity
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Canada
Posted: 1st Aug 2015 22:58
Okay, I'll give that a try right now, I think it'll work. Thanks!

Gamejolt: http://gamejolt.com/profile/united-calamity/575975
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Aug 2015 02:32
Is it a correct assumption that somewhere prior to the call, you define 'Integer' as 'int'?

And, putting agk::loadimage in a header file (or any agk command for that matter) simply won't work right. And, putting such commands in a header file ensures that there will be an attempt to execute them outside of the AppGameKit app class.

The AppGameKit engine has a set way of handling things. And you cannot do AppGameKit commands before the app::Begin method is called.

The app::Begin and agk::End methods each get called once. The app::Loop method gets executed until you do something that initiates the end process.

Cheers,
Ancient Lady
United Calamity
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Canada
Posted: 2nd Aug 2015 04:10
I'm fixing up the code right now, thanks for the help!

Gamejolt: http://gamejolt.com/profile/united-calamity/575975

Login to post a reply

Server time is: 2024-11-25 19:53:29
Your offset time is: 2024-11-25 19:53:29