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 / [SOLVED] [Tier 2] App crashes if calling AGK function from within a constructor.

Author
Message
Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 4th May 2015 03:42
Having a constructor such as the following:



That causes the app to crash with the following error:

Quote: "Unhandled exception at 0x010FFC04 in Template.exe: 0xC0000005: Access violation reading location 0x00000004."


But making the following function:


Works if I create the object and THEN call the Setup function. It crashes if I try to call Setup through the constructor.

Is there any reason for this?

The author of this post has marked a post as an answer.

Go to answer

Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 4th May 2015 05:55
Add a breakpoint at the top of the constructor and run with debugging. Step through it until it crashes and paste the line that it crashes on here so I can get a better understanding of what's happening.


Sean

Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 4th May 2015 06:04
I moved the code around a bit, and vs2013 always points at the first line in the constructor that contains an AGK:: call. I remove those calls, and it works fine. I called Text::Setup() from within the constructor, and it fails at the first call to anything in the AppGameKit name space.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 6th May 2015 18:04
It depends when the object is being constructed. If it is a global object then it might be calling its constructor before AppGameKit has had a chance to setup OpenGL.
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 7th May 2015 01:54
Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 7th May 2015 03:18
Quote: "iOS?"


I only tested in VS 2013 Debug so far.

Quote: "It depends when the object is being constructed. If it is a global object then it might be calling its constructor before AppGameKit has had a chance to setup OpenGL."


This makes sense. At what point would it be safe to make these calls? It seems to be after I get to the begin function?
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th May 2015 04:01
This post has been marked by the post author as the answer.
Yes, the Begin function is the first place that it is safe to call AppGameKit functions

Login to post a reply

Server time is: 2024-11-25 21:18:50
Your offset time is: 2024-11-25 21:18:50