• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Bigfatmeany

Error LNK2019, SDL_IMG, SLD_LoadTexture. Unsolvable problem.

21 posts in this topic

Im using SDL2 to do all my image rendering, screen creation, basically what it's used for. I'm near the end of finishing up, and I wanted to test my image loading function, The test ended in a failure. I have been trying to solve this problem for little over two hours now, and I am making no progress. this is my error.

Error	1 error LNK2019: unresolved external symbol _IMG_LoadTexture referenced in function "public: __thiscall CSprite::CSprite(struct SDL_Renderer *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,int)" (??0CSprite@@QAE@PAUSDL_Renderer@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z)	z:\my documents\visual studio 2013\Projects\SDL tuts 1\SDL tuts 1\Sprite.obj	SDL tuts 1

here is the class, and the header file.

#include "Sprite.h"
#include "includes.h"



CSprite::CSprite(SDL_Renderer *passedrenderer, std::string Filepath, int x, int y, int w, int h)
{

	renderer = passedrenderer;
	image = NULL;
	image = IMG_LoadTexture(renderer, Filepath.c_str());

	rect.x = x;
	rect.y = y;
	rect.w = w;
	rect.h = h;
}


CSprite::~CSprite()
{
	SDL_DestroyTexture(image);
}

void CSprite::Draw()
{
	SDL_RenderCopy(renderer, image, NULL, &rect);
}
#pragma once
#include "includes.h"
class CSprite
{
public:
	CSprite(SDL_Renderer *passedrenderer,std::string Filepath, int x, int y, int w, int h);
	~CSprite();

	void Draw();
private:
	SDL_Texture *image;
	SDL_Rect rect;
	SDL_Renderer *renderer;
	

};

If you need anything else, Im more than willing to give the needed resources.

0

Share this post


Link to post
Share on other sites

Normally, this means that the compiler can find the header files for the SDL_image library, by your linker is not trying to link with SDL_image.lib, and therefore cannot find the function.

Make sure you tell your linker to use SDL_image.lib, just as you did with the regular SDL library.

1

Share this post


Link to post
Share on other sites

Normally, this means that the compiler can find the header files for the SDL_image library, by your linker is not trying to link with SDL_image.lib, and therefore cannot find the function.

Make sure you tell your linker to use SDL_image.lib, just as you did with the regular SDL library.

I have double checked everything I could, I unlinked the .lib file, and as I expected the Image functions become unidentified, so I quickly re-linked it. After further testing, I have narrowed it down to this line. 

EDIT: im aware the error directly points to this line, however I was unsure if something other than this line could be causing to throw the error.

image = IMG_LoadTexture(renderer, Filepath.c_str());

more noteably, "Filepath.c_str());"

as Filepath is created as a string, and the LoadTexture function requires a const char*, I used the c_str() prefix to convert it from a string. undoing this gives me a conversion error, and converting it gives me the error listed above. So now im stuck between what seems to be a rock and a hard place.

Edited by Bigfatmeany
0

Share this post


Link to post
Share on other sites

You say that unlinking the lib-file causes other unresolved externals, right?

Now since IMG_LoadTexture is specifically added in SDL_image 2.0.0, is it possible that you use the header file of SDL2, but link to an older version of the library (.lib-file)?

0

Share this post


Link to post
Share on other sites

You say that unlinking the lib-file causes other unresolved externals, right?

Now since IMG_LoadTexture is specifically added in SDL_image 2.0.0, is it possible that you use the header file of SDL2, but link to an older version of the library (.lib-file)?

Right before I checked this post, I found my SDL2_image.dll to be corrupted, so after re-downloading it, and re-placing the old file, everything seems fine on my code end. however now im getting 

0xC0000005: Access violation reading location 0x00000000

in line 10 of this 

#include "Game_Loop.h"



CGame_Loop::CGame_Loop()
{
	csdl_setup = new CSDL_Setup(&quit);
	player = new CSprite(csdl_setup->GetRenderer(), "Z:\My Documents\Visual Studio 2013\Projects\SDL tuts 1\face.bmp", 0,0,200,200);
	quit = false;
	while ((!quit) && (csdl_setup->GetMainEvent()->type != SDL_QUIT))
	{
		csdl_setup->Begin();
		player->Draw();

			csdl_setup->End();
	}
}


CGame_Loop::~CGame_Loop()
{
}

as far as im aware this error means something is wrong with a pointer somewhere, pointing to bad memory, but I have no clue where.

0

Share this post


Link to post
Share on other sites

It is highly likely that you are not calling necessary init function - I dont know what your main() looks like but it should be calling SDL_Init somewhere before you call any SDL functions - see the SDL doc for SDLInit

 

If the SDL_Init call is in your CSDL_Setup you could step through your game loop code with your debugging tool and see exactly where the code is failing - Step in to your sld_setup->Begin() function and see the values of the object's variables

Edited by EarthBanana
0

Share this post


Link to post
Share on other sites

It is highly likely that you are not calling necessary init function - I dont know what your main() looks like but it should be calling SDL_Init somewhere before you call any SDL functions - see the SDL doc for SDLInit

 

If the SDL_Init call is in your CSDL_Setup you could step through your game loop code with your debugging tool and see exactly where the code is failing - Step in to your sld_setup->Begin() function and see the values of the object's variables

my main is fairly simple, and my SDL_init call is made first thing in the CSDL_Setup class,  and my main looks simply like this:

#include "includes.h"
#include "SDL_Setup.h"
#include "Game_Loop.h"





int main(int argc, char* args[])
{
	CGame_Loop();
	
	return 0;
}

0

Share this post


Link to post
Share on other sites
Are you sure your libraries (especially SDL_Image) are in their latest versions?

@edit
Access violations, accessing 0x000000... do you, by chance, have a global pointer that isn't allocated anywhere or something like that? Running your debugger would probably give you the line where this break happens. Edited by dejaime
0

Share this post


Link to post
Share on other sites

Are you sure your libraries (especially SDL_Image) are in their latest versions?

@edit
Access violations, accessing 0x000000... do you, by chance, have a global pointer that isn't allocated anywhere or something like that? Running your debugger would probably give you the line where this break happens.

I have nothing that is un-allocated, however as shown here, for some reason my renderer and main event are appearing null, even though they aren't and shouldn't be.

heres the line that breaks:

while (csdl_setup->GetMainEvent()->type != SDL_QUIT)

here is a picture showing them both appear as NULL and the SDL code:

 

EDIT: I couldn't get the picture to work so heres this:
 
csdl_setup = 0x01394de8 {window=0x01013050 {...} renderer=0x00000000 <NULL> mainEvent=0x00000000 <NULL> }

 

SDL code:

CSDL_Setup::CSDL_Setup(bool *quit)
{
	*quit = false; 
	if (*quit = true)
	{
		// Start SDL
		SDL_Init(SDL_INIT_EVERYTHING);
		window = SDL_CreateWindow("My First RPG!", 100, 100, 600, 480, SDL_WINDOW_SHOWN);
		if (window == NULL)
		{
			std::cout << "No window!" << std::endl;
			*quit = true;
		}
		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
		if (renderer = NULL)
		{
			std::cout << "No Renderer" << std::endl;
			*quit = true;
		}
		if (*quit = true)
		{
			//Quit SDL
			SDL_Quit();
		}

	}
}
Edited by Bigfatmeany
0

Share this post


Link to post
Share on other sites
if (renderer = NULL) {...

You are attributing NULL to the renderer here, I am sure you meant to use == .
I have done this several times.

 

Same with the quit test...

 

Didn't your compiler spit a warning about this?

Edited by dejaime
0

Share this post


Link to post
Share on other sites
if (renderer = NULL) {...

You are attributing NULL to the renderer here, I am sure you meant to use == .
I have done this several times.

 

Same with the quit test...

 

Didn't your compiler spit a warning about this?

 

ah, this solved my first error, no it didnt. which was odd. It compiles with no errors or warnings. except for the break, which is now happening here.

SDL_Renderer *CSDL_Setup::GetRenderer()
{
	return renderer;
}

more specifically

return renderer;

EDIT:

interestingly enough if I have:

csdl_setup = new CSDL_Setup(&quit);

it breaks in the original place.

however:

csdl_setup == new CSDL_Setup(&quit);

"==" causes it to break in the return renderer; function.

any known reason to why == and = are different or did i just missing something from my books and studies?

Edited by Bigfatmeany
0

Share this post


Link to post
Share on other sites

It would be easier to understand your code if you placed it (in its entirety) somewhere like PasteOfCode or Gist.

 

The CSDL_Setup class declaration would be great, while the context where you call the problematic GetRenderer() function would also help. It doesn't seem like something that should break that way...

 

btw, what compiler are you using? All compilers I know show a warning when attributing something somewhere where a "truth value" should be; unless their warnings are suppressed manually.

Edited by dejaime
0

Share this post


Link to post
Share on other sites

It would be easier to understand your code if you placed it (in its entirety) somewhere like PasteOfCode or Gist.

 

The CSDL_Setup class declaration would be great, while the context where you call the problematic GetRenderer() function would also help. It doesn't seem like something that should break that way...

 

btw, what compiler are you using? All compilers I know show a warning when attributing something somewhere where a "truth value" should be; unless their warnings are suppressed manually.

SDL_Setup.cpp http://paste.ofcode.org/h7TiTsMNJLQK9U57k9Xw7q

SDL_Setup.h http://paste.ofcode.org/9qem9BMGWj8TcqcFMFQEZJ

Game_Loop.cpp http://paste.ofcode.org/x4KRbXXgAvACvi9ch46vjx

Game_Loop.h http://paste.ofcode.org/DSpAvqcgDGQ66MEY6jKvEA

 

Im using visual studio 2013. If it is showing them, im seeing them no-where, and I know it used to throw warnings in 2010.

0

Share this post


Link to post
Share on other sites

The problem can be here:

player = new CSprite(csdl_setup->GetRenderer(), "Z:\My Documents\Visual Studio 2013\Projects\SDL tuts 1\face.bmp", 0,0,200,200);

"...\face.bmp". Try swapping all your \ with '/' or '\\' and trying again. The path is probably being misinterpreted...

player = new CSprite(csdl_setup->GetRenderer(), "Z:/My Documents/Visual Studio 2013/Projects/SDL tuts 1/face.bmp", 0,0,200,200);
Edited by dejaime
0

Share this post


Link to post
Share on other sites

 

The problem can be here:

player = new CSprite(csdl_setup->GetRenderer(), "Z:\My Documents\Visual Studio 2013\Projects\SDL tuts 1\face.bmp", 0,0,200,200);

"...\face.bmp". Try swapping all your \ with '/' or '\\' and trying again. The path is probably being misinterpreted...

player = new CSprite(csdl_setup->GetRenderer(), "Z:/My Documents/Visual Studio 2013/Projects/SDL tuts 1/face.bmp", 0,0,200,200);

that did give me a warning, i just didn't get around to changing  it, but it still breaks.

0

Share this post


Link to post
Share on other sites

Now I'll ask you for your CSprite class; I hope you don't mind!

 

interestingly enough if I have:

csdl_setup = new CSDL_Setup(&quit);

it breaks in the original place.

however:

csdl_setup == new CSDL_Setup(&quit);

"==" causes it to break in the return renderer; function.

any known reason to why == and = are different or did i just missing something from my books and studies?

Didn't see this earlier.

== is a comparison, while = is an attribution.

This:

x = 1

means that you want x to be 1, and now it is.

x == 1

means that you want to know if it is 1.

 

So, == is comparing two things,

while = is modifying the left one's value to be the same as the right one.

 

When I said the quit test, I meant this one:

if (*quit = true)
Edited by dejaime
0

Share this post


Link to post
Share on other sites

Now I'll ask you for your CSprite class; I hope you don't mind!

 

interestingly enough if I have:

csdl_setup = new CSDL_Setup(&quit);

it breaks in the original place.

however:

csdl_setup == new CSDL_Setup(&quit);

"==" causes it to break in the return renderer; function.

any known reason to why == and = are different or did i just missing something from my books and studies?

Didn't see this earlier.

== is a comparison, while = is an attribution.

This:

x = 1

means that you want x to be 1, and now it is.

x == 1

means that you want to know if it is 1.

 

So, == is comparing two things,

while = is modifying the left one's value to be the same as the right one.

see, thats what i thought. But it confuses my why visual studio 2013 wouldn't throw me a warning about that in an if check.

Sprite.cpp http://paste.ofcode.org/xDsSHHcNbL8YWhjscfkWnh

sprite.h http://paste.ofcode.org/u8Jb28PZAUTux7PfrhJG8Y

Edited by Bigfatmeany
0

Share this post


Link to post
Share on other sites

Are you sure the csdl_setup is a valid pointer? Where is it constructed?

private:
	bool quit;
	CSprite *player;
	CSDL_Setup *csdl_setup;
};

game_loop.h

0

Share this post


Link to post
Share on other sites
I'll try and help you by PM (top right corner).
So we stop bumping the thread all the time!

cheers
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0