Coder Social home page Coder Social logo

Comments (4)

Dobby233Liu avatar Dobby233Liu commented on August 19, 2024

creation date = 2009-03-04T08:37:50.153-08:00

I think I've fixed it by moving the DataIsLoaded check to GetNextLang and doing a recursive loop there rather than the iterative approach, but I'm haunted by the feeling this might result in a stack overflow.

from anolis.

Dobby233Liu avatar Dobby233Liu commented on August 19, 2024

creation date: 2009-03-04T10:38:09.033-08:00

Your problem most likely derives from:

ResourceLang lang = GetNextLang();
			
			if( _onlyLoaded ) {
				
				while( !lang.DataIsLoaded ) {
					
					lang = GetNextLang();
					
					if(lang == null) return false;
				}

There may be the case where you are using the dot operator on lang when it is null (as GetNextLang may return null). Either go for a try/catch, or a do/while instead of while/do, something like this:

ResourceLang lang;

if (_onlyLoaded) do
{
lang = GetNextLang();
if (lang == null) return false;
} 
while (!lang.DataIsLoaded);

This is the safe way of doing it, as while condition doesn't get evaluated if there's no language

from anolis.

Dobby233Liu avatar Dobby233Liu commented on August 19, 2024

creation date = 2009-03-04T12:37:19.763-08:00

Thanks dexter, that was the problem.

Disregard my earlier comment at 16:37 today, my recursive approach was buggy and I've since independently came to the same solution as you to use a do/while but I didn't use the guard expression like that. This is my solution:

			ResourceLang lang;
			
			do {
				
				lang = GetNextLang();
				
				if( lang == null ) return false; // lang will be null when all the langs have been iterated through
				
			} while( _onlyLoaded && !lang.DataIsLoaded );
			
			_currentData = lang.Data; // this may lazy-load the data
			return true;

It will be included in the next check-in.

from anolis.

Dobby233Liu avatar Dobby233Liu commented on August 19, 2024

closed date = 2009-03-14T17:42:28.823-07:00

from anolis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.