这个例外是什么,我该如何删除它?我一直在glutmainloop得到它 [英] What is this exception and how do I remove it? I keep getting it at glutmainloop

查看:81
本文介绍了这个例外是什么,我该如何删除它?我一直在glutmainloop得到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有openGL项目的代码,但我得到这个异常

hi , i have code for openGL project but i get this exception "

Quote:

访问冲突写入位置0x000000D4。

Access violation writing location 0x000000D4.

<这是代码





here is the code

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include <Windows.h>
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
void renderscene()
{

	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 0.3, 0.0);

	char c1[] = "COMPUTER GRAPHICS PROJECT";
	glRasterPos2f(600, 375);
	for (int i = 0; c1[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c1[i]);

	char c2[] = "NAME:";
	glRasterPos2f(700.0, 350.0);
	for (int i = 0; c2[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c2[i]);

	char c3[] = "COLLEGE:";
	glRasterPos2f(700.0, 325.0);
	for (int i = 0; c3[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c3[i]);

	char c4[] = "";
	glRasterPos2f(700.0, 300.0);
	for (int i = 0; c4[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c4[i]);

	char c5[] = "Press right button of mouse to get various options";
	glRasterPos2f(300.0, 200.0);
	for (int i = 0; c5[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c5[i]);
	glFlush();

}


void init()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glColor3f(0.0f, 0.0f, 0.0f);
	glPointSize(0.8);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 2000.0, 0.0, 400.0);
}
struct node
{
	int info;
	struct node *rlink;
	struct node *llink;
};
typedef struct node *NODE;
static int count = 0;
NODE head;
int h[100];
struct arr
{
	int p;
	int q;
}m[100];

NODE getnode()
{
	NODE temp;
	temp = (NODE)malloc(sizeof(struct node));
	if (temp == NULL)
	{
		printf("out of memory\n");
		exit(1);
	}
	return temp;
}
void disp()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 0.0, 1.0);
	char c[] = "List is Empty";
	glRasterPos2f(800.0, 200.0);
	for (int i = 0; c[i] != '\0'; i++)
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c[i]);
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_POLYGON);
	glVertex2i(100, 200);
	glVertex2i(100, 225);
	glVertex2i(500, 225);
	glVertex2i(500, 200);
	glEnd();
	glFlush();
}
NODE display(NODE head)
{
	glClear(GL_COLOR_BUFFER_BIT);
	NODE temp;
	int i = 0, k, j = 0;
	temp = head->rlink;
	if (temp == head)
	{
		printf(" list is empty\n");
		disp();
		return head;

	}
	printf("elements are\n");

	while (temp != head)
	{
		for (k = 0; k<count; k++)
		{
			GLfloat x1 = 100, x2 = 150, x3 = 350, x4 = 400, x5 = 500, x6 = 480, x7 = 20, x9 = 0;
			h[j] = temp->info;
			printf("%d\n", h[j]);
			glColor3f(0.0, 0.0, 0.0);
			char c[] = "Info";
			glRasterPos2f(220.0, 230.0);
			for (int a = 0; c[a] != '\0'; a++)
				glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, c[a]);
			glColor3f(1.0, 0.0, 0.0);
			glBegin(GL_POLYGON);
			glVertex2i(x2 + k * 400, 200);
			glVertex2i(x2 + k * 400, 225);
			glVertex2i(x3 + k * 400, 225);
			glVertex2i(x3 + k * 400, 200);
			glEnd();
			glColor3f(0.0, 0.0, 0.0);
			char r[] = "rlink";
			glRasterPos2f(355.0, 230.0);
			for (int b = 0; r[b] != '\0'; b++)
				glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, r[b]);
			glColor3f(0.0, 0.0, 1.0);
			glBegin(GL_POLYGON);
			glVertex2i(x3 + k * 400, 225);
			glVertex2i(x3 + k * 400, 200);
			glVertex2i(x4 + k * 400, 200);
			glVertex2i(x4 + k * 400, 225);
			glEnd();
			glColor3f(0.0, 0.0, 0.0);
			char s[] = "llink";
			glRasterPos2f(120.0, 230.0);
			for (int d = 0; s[d] != '\0'; d++)
				glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, s[d]);
			glColor3f(0.0, 1.0, 0.0);
			glBegin(GL_POLYGON);
			glVertex2i(x1 + k * 400, 225);
			glVertex2i(x1 + k * 400, 200);
			glVertex2i(x2 + k * 400, 200);
			glVertex2i(x2 + k * 400, 225);
			glEnd();
			glColor3f(0.0, 1.0, 0.0);
			glBegin(GL_LINES);
			glVertex2i(x1 + k * 400, 207);
			glVertex2i(x9 + k * 400, 207);
			glVertex2i(x9 + k * 400, 207);
			glVertex2i(x7 + k * 400, 202);
			glVertex2i(x9 + k * 400, 207);
			glVertex2i(x7 + k * 400, 210);
			glColor3f(0.0, 0.0, 1.0);
			glBegin(GL_LINES);
			glVertex2i(x4 + k * 400, 215);
			glVertex2i(x5 + k * 400, 215);
			glVertex2i(x5 + k * 400, 215);
			glVertex2i(x6 + k * 400, 210);
			glVertex2i(x5 + k * 400, 215);
			glVertex2i(x6 + k * 400, 219);
			glEnd();
			m[i].p = h[j] / 10;
			m[i].q = h[j] % 10;
			m[i].p = m[i].p + 48;
			m[i].q = m[i].q + 48;
			int x8 = 225;
			glColor3f(0.0, 0.0, 0.0);
			glRasterPos2i(x8 + k * 400, 210);
			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, m[i].p);
			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, m[i].q);
			i++;
			j++;
			temp = temp->rlink;
			glFlush();
		}
	}
	return head;
}
NODE insertfront(NODE head, int item)
{
	NODE temp, cur;
	temp = getnode();
	temp->info = item;
	cur = head->rlink;
	head->rlink = temp;
	temp->llink = head;
	temp->rlink = cur;
	cur->llink = temp;
	return head;

}
NODE insertrear(NODE head, int item)
{
	NODE temp, cur;
	temp = getnode();
	temp->info = item;
	cur = head->llink;
	head->llink = temp;
	temp->rlink = head;
	temp->llink = cur;
	cur->rlink = temp;
	return head;
}
NODE insertleft(NODE head, int ele)
{
	int item;
	NODE temp, cur, pre;
	if (head->rlink == head)
	{
		printf("list is empty\n");
		count--;
		return head;
	}
	cur = head->rlink;
	while (cur != head)
	{
		if (cur->info == ele)
			break;
		cur = cur->rlink;
	}
	if (cur == head)
	{
		printf("%d element not found\n", ele);
		count--;
		return head;
	}
	printf("enter element to be inserted\n");
	scanf_s("%d", &item);
	pre = cur->llink;
	temp = getnode();
	temp->info = item;
	temp->llink = pre;
	temp->rlink = cur;
	cur->llink = temp;
	pre->rlink = temp;
	return head;

}
NODE insertright(NODE head, int ele)
{
	int item;
	glClear(GL_COLOR_BUFFER_BIT);
	NODE temp, cur, next;
	if (head->rlink == head)
	{
		printf("list is empty\n");
		count--;
		return head;
	}
	cur = head->rlink;
	while (cur != head)
	{
		if (cur->info == ele)
		{
			printf("enter element to be inserted\n");
			scanf_s("%d", &item);
			next = cur->rlink;
			temp = getnode();
			temp->info = item;
			temp->llink = cur;
			temp->rlink = next;
			cur->rlink = temp;
			next->llink = temp;
			return head;
		}
		cur = cur->rlink;
	}
	printf("%d element not found\n", ele);
	count--;
	return head;
}
NODE deletfront(NODE head)
{
	NODE cur, next;
	if (head->rlink == head)
	{
		printf("list is empty\n");
		count++;
		return head;
	}
	cur = head->rlink;
	next = cur->rlink;
	head->rlink = next;
	next->llink = head;
	printf("node to b deleted is %d\n", cur->info);
	free(cur);
	return head;
}
NODE deletrear(NODE head)
{
	NODE cur, prev;
	if (head->llink == head)
	{
		printf("list is empty\n");
		count++;
		return head;
	}
	cur = head->llink;
	prev = cur->llink;
	head->llink = prev;
	prev->rlink = head;
	printf("node to b deleted is %d\n", cur->info);
	free(cur);
	return head;
}

NODE del(NODE head, int ele)
{
	NODE cur, next, pre;
	glClear(GL_COLOR_BUFFER_BIT);
	if (head->rlink == head)
	{
		printf("list is empty\n");
		count++;
		return head;
	}
	cur = head->rlink;
	while (cur != head)
	{
		if (cur->info == ele)
			break;
		cur = cur->rlink;
	}
	if (cur == head)
	{
		printf("%d element not found\n", ele);
		count++;
		return head;
	}
	pre = cur->llink;
	next = cur->rlink;
	printf("%d element found and deleted\n", ele);
	pre->rlink = next;
	next->llink = pre;
	free(cur);
	return head;

}


void top_menu(int option)
{
	int ele;
	switch (option)
	{
	case 1:

		printf("enter item to be inserted\n");
		scanf_s("%d", &ele);
		head = insertfront(head, ele);
		count++;
		display(head);
		break;
	case 2:
		printf("enter item to be inserted\n");
		scanf_s("%d", &ele);
		head = insertrear(head, ele);
		count++;
		display(head);
		break;
	case 3:
		printf("enter key to be searched\n");
		scanf_s("%d", &ele);
		head = insertleft(head, ele);
		count++;
		display(head);
		break;
	case 4:
		printf("enter key to be searched\n");
		scanf_s("%d", &ele);
		head = insertright(head, ele);
		count++;
		display(head);
		break;
	case 5:
		head = deletfront(head);
		count--;
		display(head);
		break;
	case 6:
		head = deletrear(head);
		count--;
		display(head);
		break;
	case  7:printf("enter key\n");
		scanf_s("%d", &ele);
		count--;
		head = del(head, ele);
		display(head);
		break;
	case 8:exit(0);
	}
}
void main(int argc, char**argv)
{
	head = getnode();
	head->rlink = head;
	head->llink = head;
	head->info = NULL;
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(700, 500);
	glutInitWindowPosition(0, 0);
	glutCreateWindow("Doubly Linked List");
	glutCreateMenu(top_menu);
	glutAddMenuEntry("InsertFront", 1);
	glutAddMenuEntry("InsertRear", 2);
	glutAddMenuEntry("InsertLeft", 3);
	glutAddMenuEntry("InsertRight", 4);
	glutAddMenuEntry("DeleteFront", 5);
	glutAddMenuEntry("DeleteRear", 6);
	glutAddMenuEntry("DeletSpecified", 7);
	glutAddMenuEntry("Exit", 8);
	glutAttachMenu(GLUT_RIGHT_BUTTON);
	glutDisplayFunc(renderscene);
	init();
	glutMainLoop();		
}





我的尝试:



我没有尝试任何东西,因为我无法理解任何东西



What I have tried:

I haven't tried anything as i can't understand anything

推荐答案

为什么你在 std :: list [ ^ ]可用(且可靠)?



如果你真的想要使用它然后你首先要确保它可靠地工作,就是编写测试用例来隔离它(没有 OpenGL 交互)。
Why are you using your own implementation of double linked list when std::list[^] is available (and reliable)?

If you really want to use it then you have first to make sure it reliably works, that is write test cases to check it, in isolation (that is without OpenGL interaction).


如果你想解决这个问题,现在是时候了解一下了。至少,是时候学习如何使用调试器了。你没有提到你的开发环境,所以我假设它是一个有一个像样的调试器。如果它没有,那么找一个尽快做的另一个。一个好的调试器将显示程序崩溃的确切位置,您可以检查调用堆栈以找到更多详细信息。这是调试器的主要目的之一。
If you want to solve this problem it is time to get some understanding. At minimum, it's time to learn how to use your debugger. You have made no mention of your development environment so I will assume that it is one with a decent debugger. If it doesn't have one then find a different one that does as soon as possible. A good debugger will show you exactly where the program crashes and you can examine the call stack to find out more details. That is one of the primary purposes of a debugger.


这篇关于这个例外是什么,我该如何删除它?我一直在glutmainloop得到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆